メインコンテンツまでスキップ

API reference for Momento Cache

Control APIs

These API methods are used to manage and control caches.

Create cache

Creates a cache with the provided name

Attributes:

NameTypeDescription
cacheNameStringName of the cache to be created.

const authToken="eyJhbGc.MyTestToken";
const defaultTTL = 15;
const momento = new SimpleCacheClient(authToken, defaultTtl);
momento.createCache('test-cache');

Delete cache

Deletes a cache

Attributes:

NameTypeDescription
cacheNameStringName of the cache to be deleted.

const authToken="eyJhbGc.MyTestToken";
const defaultTTL = 15;
const momento = new SimpleCacheClient(authToken, defaultTtl);
momento.deleteCache('test-cache');

List caches

Lists all caches for the provided auth token.

NameTypeDescription
nextTokenStringToken for pagination of caches.

Flush cache

Flushes all data from a cache

Attributes:

NameTypeDescription
cacheNameStringName of the cache to be flushed.
ヒント

While you could use Delete Cache, then Create Cache to mimic this, the FlushCache API keeps the settings and only deletes the data in the cache.

Data APIs

These API methods are used to directly interact with data in a cache.

Set

Sets the value in cache with a given Time To Live (TTL) seconds. If a value for this key is already present it will be replaced by the new value.

NameTypeDescription
cacheNameStringName of the cache.
key[]ByteThe key under which the value is to be added.
value[]ByteThe value to be stored.
ttlSecondsintTime to Live for the item in Cache.

const authToken="eyJhbGc.MyTestToken";
const defaultTTL = 15;
const momento = new SimpleCacheClient(authToken, defaultTtl);
momento.set('test-cache', 'test-key', 'test-value');

Get

Get the cache value stored for the given key.

NameTypeDescription
cacheNameStringName of the cache.
key[]ByteThe key under which the value is to be added.

const authToken="eyJhbGc.MyTestToken";
const defaultTTL = 15;
const momento = new SimpleCacheClient(authToken, defaultTtl);
momento.get('test-cache', 'test-key');

Delete

Delete the cache value stored for the given key.

NameTypeDescription
cacheNameStringName of the cache.
key[]ByteThe key under which the value is to be deleted.

const authToken="eyJhbGc.MyTestToken";
const defaultTTL = 15;
const momento = new SimpleCacheClient(authToken, defaultTtl);
momento.delete('test-cache', 'test-key');

Increment

Adds to the value of a field, if and only if the existing value is a UTF-8 string representing a base 10 integer. If the field does not exist, this method sets the field's value to the amount to increment by.

NameTypeDescription
cacheNameStringName of the cache.
fieldStringThe key under which the value is to be deleted.
amountIntegerThe quantity to add to the value. May be positive, negative, or zero. Defaults to 1.
注記

The resulting incremented value must be between -9223372036854775808 and 9223372036854775807, ie. a signed 64-bit integer. If not, there will be an error response.

Ping

Sends a ping to the server. This API can be used for checking connectivity to confirm that the client can connect to the server successfully.

Method response object
* Success
* Error

See [response objects](/ja/develop/api-reference/response-objects) for specific information.

KeyExists

Checks if a provided key exists in the cache.

NameTypeDescription
cacheNameStringName of the cache.
keyString | byteKey which is to be checked for its existence in the cache.
Method response object
* Success
- `exists()`: bool
* Error

See [response objects](/ja/develop/api-reference/response-objects) for specific information.

KeysExist

Checks if provided keys exist in the cache.

NameTypeDescription
cacheNameStringName of the cache.
keysString[] | byte[]Keys which are to be checked for their existence in the cache.
Method response object
* Success
- `exists()`: bool[]
* Error

See [response objects](/ja/develop/api-reference/response-objects) for specific information.

SetIfNotExists

Associates the provided value to a cache item with a given key.

NameTypeDescription
cacheNameStringName of the cache.
keyString /bytes
valueString /bytes
ttlSecondsDurationTime to Live for the item in Cache.
Method response object
* Stored
* NotStored
* Error

See [response objects](/ja/develop/api-reference/response-objects) for specific information.

Time to Live APIs

These APIs apply across all cache types.

UpdateTtl

Overwrites the TTL of a cache item with the provided value in seconds.

NameTypeDescription
cacheNameStringName of the cache.
keyString | bytesThe key under which the value's TTL is to be updated.
ttlDurationTime to live that you want to update in cache in seconds.

IncreaseTtl

Increase the TTL seconds for a key to the provided value only if it would increase the TTL.

Examples

  • If the TTL is 5 seconds and is increased to 6 seconds, the new TTL will be 6 seconds.
  • If the TTL is 5 seconds and is increased to 3 seconds, the TTL will not be increased.
NameTypeDescription
cacheNameStringName of the cache.
keyString | bytesThe key under which the value's TTL is to be increased.
ttlDurationTime to live that you want to increase to.

DecreaseTtl

Decrease the TTL seconds for a key to the provided value only if it would decrease the TTL.

Examples

  • If the TTL is 5 seconds and is decreased to 3 seconds, the new TTL will be 3 seconds.
  • If the TTL is 5 seconds and is decreased to 6 seconds, the TTL will not be decreased.
NameTypeDescription
cacheNameStringName of the cache.
keyString | bytesThe key under which the value's TTL is to be decreased.
ttlDurationTime to live that you want to decrease to.

Collection data types (CDTs)

Collections may contain different types of structures depending on your use case. Supported data types are:

  • Dictionaries are used to store unordered field:value pairs.
  • Lists are a collection of ordered elements, sorted in the sequence each element was inserted.
  • Sets are an unordered collection of unique elements in string format.

For more in-depth information on usage, see collection data types.

Current status of API support in SDKs

Feature.NETJavaNode.jsPythonPHPRubyGoRust
Control APIs
Get/Set
Increment
Dictionary CDTs
Set CDTs
List CDTs
Flush Cache