Documentation

mps.cache.connect

Connect to cache, or create a cache if it doesn't exist

Syntax

c = mps.cache.connect(cacheName)
c = mps.cache.connect(cacheName,'Connection',connectionName)

Description

example

c = mps.cache.connect(cacheName) connects to a cache when there's a single connection to a persistence service.

c = mps.cache.connect(cacheName,'Connection',connectionName) connects to a cache using the connection specified by connectionName when there are multiple connections to a persistence service.

Examples

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.

When you have a single connection, you do not need to specify the connection name to mps.cache.connect.

ctrl = mps.cache.control('myRedisConnection','Redis','Port',4519)
start(ctrl)
c = mps.cache.connect('myCache');
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.

When you have multiple connections to a persistence service, create a cache by specifying the connection name associated with the service you want to use.

ctrl_1 = mps.cache.control('myRedisConnection1','Redis','Port',4519)
start(ctrl_1)
ctrl_2 = mps.cache.control('myRedisConnection2','Redis','Port',4520)
start(ctrl_2)
c = mps.cache.connect('myCache','Connection','myRedisConnection1')
c = 

RedisCache with properties:

          Host: 'localhost'
          Port: 4519
          Name: 'myCache'
    Operations: "read | write | create | update"
     LocalKeys: {}
    Connection: 'myRedisConnection1'

Use getp instead of dot notation to access properties.

Input Arguments

collapse all

Cache name to connect to or create, specified as a character vector.

Example: 'myCache'

Name of connection to persistence service, specified as a character vector.

Example: 'Connection','myRedisConnection'

Output Arguments

collapse all

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.

Introduced in R2018b