Main Content


Represent cache concept in MATLAB code


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.


Create a persistence provider-specific subclass of mps.cache.DataCache using mps.cache.connect.


See provider-specific subclasses for properties.

Object Functions

mps.cache.connectConnect to cache, or create a cache if it doesn't exist
bytesReturn the number of bytes of storage used by value stored at each key
clearRemove all keys and values from cache
flushWrite all locally modified keys to the persistence service
getFetch values of keys from cache
getpGet the value of a public cache property
isKeyDetermine if the cache contains specified keys
keysGet all keys from cache
lengthNumber of key-value pairs in the data cache
purgeFlush all local data to the persistence service
putWrite key-value pairs to cache
removeRemove keys from cache
retainStore remote keys from cache locally or return locally stored keys


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);
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

See Also