mps.cache.DataCache
Represent cache concept in MATLAB code
Description
mps.cache.DataCache
represents the concept of cache in MATLAB® code. It is an abstract class that serves as a superclass for each persistence
provider-specific data cache class.
Currently, Redis™ and MATLAB are the only supported persistence providers. Therefore, the cache objects will be
of type mps.cache.RedisCache
or
mps.cache.MATFileCache
.
Creation
Create a persistence provider-specific subclass of mps.cache.DataCache
using mps.cache.connect
.
Properties
See provider-specific subclasses for properties.
Object Functions
mps.cache.connect | Connect to cache, or create a cache if it doesn't exist |
bytes | Return the number of bytes of storage used by value stored at each key |
clear | Remove all keys and values from cache |
flush | Write all locally modified keys to the persistence service |
get | Fetch values of keys from cache |
getp | Get the value of a public cache property |
isKey | Determine if the cache contains specified keys |
keys | Get all keys from cache |
length | Number of key-value pairs in the data cache |
purge | Flush all local data to the persistence service |
put | Write key-value pairs to cache |
remove | Remove keys from cache |
retain | Store remote keys from cache locally or return locally stored keys |
Examples
Connect to a Redis Cache
Start a persistence service that uses Redis as the persistence provider. The service requires a connection name and an open port. Once the service is running, you can connect to the service using the connection name and create a cache.
ctrl = mps.cache.control('myRedisConnection','Redis','Port',4519); start(ctrl) c = mps.cache.connect('myCache', 'Connection', 'myRedisConnection')
c = RedisCache with properties: Host: 'localhost' Port: 4519 Name: 'myCache' Operations: "read | write | create | update" LocalKeys: {} Connection: 'myRedisConnection' Use getp instead of dot notation to access properties.
Version History
Introduced in R2018b