主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

mps.cache.connect

连接到缓存,如果不存在则创建缓存

说明

当与持久性服务有单一连接时,c = mps.cache.connect(cacheName) 连接到缓存。

示例

c = mps.cache.connect(cacheName,'Connection',connectionName) 当与持久性服务有多个连接时,使用 connectionName 指定的连接连接到缓存。

示例

全部折叠

启动使用 Redis™ 作为持久性提供程序的持久性服务。该服务需要一个连接名称和一个开放端口。该服务运行后,您可以使用连接名称连接到该服务并创建缓存。

当您有一个连接时,您不需要向 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.

当您与持久性服务有多个连接时,请通过指定与要使用的服务关联的连接名称来创建缓存。

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.

输入参数

全部折叠

要连接或创建的缓存名称,指定为字符向量。

示例: 'myCache'

与持久性服务的连接名称,指定为字符向量。

示例: 'Connection','myRedisConnection'

输出参量

全部折叠

持久性提供程序特定的数据缓存对象。

目前,仅支持 Redis 和 MATLAB® 两个持久性提供程序。因此,缓存对象的类型将为 mps.cache.RedisCachemps.cache.MATFileCache

版本历史记录

在 R2018b 中推出