Momento Cache API リファレンス
コントロールAPI
これらのAPIメ ソッドは、cacheを管理・制御するために使用されます。
Create cache
指定された名前のcacheを作成します。
属性:
名前 | 型 | 説明 |
---|---|---|
cacheName | String | 作成するcacheの名前。 |
- JavaScript
- Python
- Java
- Kotlin
- Go
- C#
- PHP
- Rust
- Elixir
- Swift
- Dart
const result = await cacheClient.createCache(cacheName);
switch (result.type) {
case CreateCacheResponse.AlreadyExists:
console.log(`Cache '${cacheName}' already exists`);
break;
case CreateCacheResponse.Success:
console.log(`Cache '${cacheName}' created`);
break;
case CreateCacheResponse.Error:
throw new Error(
`An error occurred while attempting to create cache '${cacheName}': ${result.errorCode()}: ${result.toString()}`
);
}
備考
Full example code and imports can be found here
create_cache_response = await cache_client.create_cache("test-cache")
match create_cache_response:
case CreateCache.Success():
print("Cache 'test-cache' created")
case CreateCache.CacheAlreadyExists():
print("Cache 'test-cache' already exists.")
case CreateCache.Error() as error:
print(f"An error occurred while attempting to create cache 'test-cache': {error.message}")
備考
Full example code and imports can be found here
final CacheCreateResponse response = cacheClient.createCache("test-cache").join();
if (response instanceof CacheCreateResponse.Success) {
System.out.println("Cache 'test-cache' created");
} else if (response instanceof CacheCreateResponse.Error error) {
if (error.getErrorCode() == MomentoErrorCode.ALREADY_EXISTS_ERROR) {
System.out.println("Cache 'test-cache' already exists");
} else {
throw new RuntimeException(
"An error occurred while attempting to create cache 'test-cache': "
+ error.getErrorCode(),
error);
}
}
備考
Full example code and imports can be found here
when (val response = cacheClient.createCache("test-cache")) {
is CacheCreateResponse.Success -> println("Cache 'test-cache' created")
is CacheCreateResponse.AlreadyExists -> println("Cache 'test-cache' already exists")
is CacheCreateResponse.Error -> throw RuntimeException(
"An error occurred while attempting to create cache 'test-cache': ${response.errorCode}", response
)
}