Main Content


Store remote keys from cache locally or return locally stored keys



retain(c,remoteKeys) stores keys from cache locally.


localKeys = retain(c) returns a cell array of keys stored locally.


collapse all

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

Add keys and values to the cache.

put(c,'keyOne',10,'keyTwo',20,'keyThree',30,'keyFour',[400 500],'keyFive',magic(5))

Retain a few keys locally and check local keys.

localKeys = retain(c)
localKeys =

  1×2 cell array

    {'keyThree'}    {'keyFour'}

Input Arguments

collapse all

A data cache represented by a persistence provider specific data cache object.

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.

Example: c

Remote keys to store locally, specified as a cell array of character vectors.

Example: {'keyThree','keyFour'}

Output Arguments

collapse all

Locally stored keys, returned as a cell array of character vectors.


  • As a performance optimization you may choose to temporarily store a set of keys and their values in your MATLAB session or worker instead of the persistence service. Keys retained in the this fashion will be automatically written to the persistence service (see flush) when MATLAB exits or when the first function call returns.

  • Manually control the lifetime of retained keys with the flush and purge methods.

Version History

Introduced in R2018b

See Also

| | |