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
)
}
備考
Full example code and imports can be found here
_, err := client.CreateCache(ctx, &momento.CreateCacheRequest{
CacheName: cacheName,
})
if err != nil {
panic(err)
}
備考
Full example code and imports can be found here
var result = await cacheClient.CreateCacheAsync("test-cache");
if (result is CreateCacheResponse.Success)
{
Console.WriteLine("Cache 'test-cache' created");
}
else if (result is CreateCacheResponse.CacheAlreadyExists)
{
Console.WriteLine("Cache 'test-cache' already exists");
}
else if (result is CreateCacheResponse.Error error)
{
throw new Exception($"An error occurred while attempting to create cache 'test-cache': {error.ErrorCode}: {error}");
}
備考
Full example code and imports can be found here
$create_cache_response = $cache_client->createCache($cache_name);
if ($create_cache_response->asSuccess()) {
print("Cache $cache_name created\n");
} elseif ($create_cache_response->asAlreadyExists()) {
print("Cache $cache_name already exists\n");
} elseif ($err = $create_cache_response->asError()) {
print("An error occurred while attempting to create $cache_name: {$err->errorCode()} - {$err->message()}\n");
}
備考
Full example code and imports can be found here
match cache_client.create_cache(cache_name).await? {
CreateCacheResponse::Created => println!("Cache {} created", cache_name),
CreateCacheResponse::AlreadyExists => println!("Cache {} already exists", cache_name),
}
備考
Full example code and imports can be found here
case Momento.CacheClient.create_cache(client, "test-cache") do
{:ok, _} ->
IO.puts("Cache 'test-cache' created")
:already_exists ->
:ok
{:error, error} ->
IO.puts(
"An error occurred while attempting to create cache 'test-cache': #{error.error_code}"
)
raise error
end
備考
Full example code and imports can be found here
let result = await cacheClient.createCache(cacheName: cacheName)
switch result {
case .alreadyExists(_):
print("Cache already exists!")
case .success(_):
print("Successfully created the cache!")
case .error(let err):
print("Unable to create the cache: \(err)")
exit(1)
}
備考
Full example code and imports can be found here
final result = await cacheClient.createCache("test-cache");
switch (result) {
case CreateCacheAlreadyExists():
print("Cache already exists");
case CreateCacheError():
print("Error creating cache: $result");
case CreateCacheSuccess():
print("Successfully created the cache");
}
備考
Full example code and imports can be found here
Delete cache
cacheを削除します。
属性:
名前 | 型 | 説明 |
---|---|---|
cacheName | String | 削除するcacheの名前。 |
- JavaScript
- Python
- Java
- Kotlin
- Go
- C#
- PHP
- Rust
- Elixir
- Swift
- Dart
const result = await cacheClient.deleteCache(cacheName);
switch (result.type) {
case DeleteCacheResponse.Success:
console.log(`Cache '${cacheName}' deleted`);
break;
case DeleteCacheResponse.Error:
throw new Error(
`An error occurred while attempting to delete cache '${cacheName}': ${result.errorCode()}: ${result.toString()}`
);
}
備考
Full example code and imports can be found here
delete_cache_response = await cache_client.delete_cache("test-cache")
match delete_cache_response:
case DeleteCache.Success():
print("Cache 'test-cache' deleted")
case DeleteCache.Error() as error:
raise Exception(f"An error occurred while attempting to delete 'test-cache': {error.message}")
備考
Full example code and imports can be found here
final CacheDeleteResponse response = cacheClient.deleteCache("test-cache").join();
if (response instanceof CacheDeleteResponse.Success) {
System.out.println("Cache 'test-cache' deleted");
} else if (response instanceof CacheDeleteResponse.Error error) {
throw new RuntimeException(
"An error occurred while attempting to delete cache 'test-cache': "
+ error.getErrorCode(),
error);
}
備考
Full example code and imports can be found here
when (val response = cacheClient.deleteCache("test-cache")) {
is CacheDeleteResponse.Success -> println("Cache 'test-cache' deleted")
is CacheDeleteResponse.Error -> throw RuntimeException(
"An error occurred while attempting to delete cache 'test-cache': ${response.errorCode}", response
)
}
備考
Full example code and imports can be found here
_, err := client.DeleteCache(ctx, &momento.DeleteCacheRequest{
CacheName: cacheName,
})
if err != nil {
panic(err)
}
備考
Full example code and imports can be found here
var result = await cacheClient.DeleteCacheAsync("test-cache");
if (result is DeleteCacheResponse.Success)
{
Console.WriteLine("Cache 'test-cache' deleted");
}
else if (result is DeleteCacheResponse.Error error)
{
throw new Exception($"An error occurred while attempting to delete cache 'test-cache': {error.ErrorCode}: {error}");
}
備考
Full example code and imports can be found here
$delete_cache_response = $cache_client->deleteCache($cache_name);
if ($err = $delete_cache_response->asError()) {
print("An error occurred while attempting to delete $cache_name: {$err->errorCode()} - {$err->message()}\n");
} else {
print("Cache $cache_name deleted\n");
}
備考
Full example code and imports can be found here
cache_client.delete_cache(cache_name).await?;
println!("Cache {} deleted", cache_name);
備考
Full example code and imports can be found here
case Momento.CacheClient.delete_cache(client, "test-cache") do
{:ok, _} ->
IO.puts("Cache 'test-cache' deleted")
{:error, error} ->
IO.puts(
"An error occurred while attempting to delete cache 'test-cache': #{error.error_code}"
)
raise error
end
備考
Full example code and imports can be found here
let result = await cacheClient.deleteCache(cacheName: cacheName)
switch result {
case .success(let success):
print("Successfully deleted the cache")
case .error(let err):
print("Unable to delete cache: \(err)")
exit(1)
}
備考
Full example code and imports can be found here
final result = await cacheClient.deleteCache("test-cache");
switch (result) {
case DeleteCacheError():
print("Error deleting cache: $result");
exit(1);
case DeleteCacheSuccess():
print("Successfully deleted cache");
}
備考
Full example code and imports can be found here
List caches
すべてのcacheのリストを返します。
- JavaScript
- Python
- Java
- Kotlin
- Go
- C#
- PHP
- Rust
- Elixir
- Swift
- Dart
const result = await cacheClient.listCaches();
switch (result.type) {
case ListCachesResponse.Success:
console.log(
`Caches:\n${result
.getCaches()
.map(c => c.getName())
.join('\n')}\n\n`
);
break;
case ListCachesResponse.Error:
throw new Error(`An error occurred while attempting to list caches: ${result.errorCode()}: ${result.toString()}`);
}
備考
Full example code and imports can be found here
print("Listing caches:")
list_caches_response = await cache_client.list_caches()
match list_caches_response:
case ListCaches.Success() as success:
for cache_info in success.caches:
print(f"- {cache_info.name!r}")
case ListCaches.Error() as error:
raise Exception(f"An error occurred while attempting to list caches: {error.message}")
備考
Full example code and imports can be found here
final CacheListResponse response = cacheClient.listCaches().join();
if (response instanceof CacheListResponse.Success success) {
final String caches =
success.getCaches().stream().map(CacheInfo::name).collect(Collectors.joining("\n"));
System.out.println("Caches:\n" + caches);
} else if (response instanceof CacheListResponse.Error error) {
throw new RuntimeException(
"An error occurred while attempting to list caches: " + error.getErrorCode(), error);
}
備考
Full example code and imports can be found here
when (val response: CacheListResponse = cacheClient.listCaches()) {
is CacheListResponse.Success -> {
val caches: String = response.caches.joinToString("\n") { cacheInfo -> cacheInfo.name }
println("Caches:\n$caches")
}
is CacheListResponse.Error -> throw RuntimeException(
"An error occurred while attempting to list caches: ${response.errorCode}", response
)
}
備考
Full example code and imports can be found here
resp, err := client.ListCaches(ctx, &momento.ListCachesRequest{})
if err != nil {
panic(err)
}
switch r := resp.(type) {
case *responses.ListCachesSuccess:
log.Printf("Found caches %+v\n", r.Caches())
}
備考
Full example code and imports can be found here
var result = await cacheClient.ListCachesAsync();
if (result is ListCachesResponse.Success success)
{
Console.WriteLine($"Caches:\n{string.Join("\n", success.Caches.Select(c => c.Name))}\n\n");
}
else if (result is ListCachesResponse.Error error)
{
throw new Exception($"An error occurred while attempting to list caches: {error.ErrorCode}: {error}");
}
備考
Full example code and imports can be found here
$list_caches_response = $cache_client->listCaches();
if ($success = $list_caches_response->asSuccess()) {
print("Found caches:\n");
foreach ($success->caches() as $cache) {
$cache_name = $cache->name();
print("- $cache_name\n");
}
} elseif ($err = $list_caches_response->asError()) {
print("An error occurred while attempting to list caches: {$err->errorCode()} - {$err->message()}\n");
}
備考
Full example code and imports can be found here
let response = cache_client.list_caches().await?;
println!("Caches: {:#?}", response.caches);
備考
Full example code and imports can be found here
case Momento.CacheClient.list_caches(client) do
{:ok, result} ->
IO.puts("Caches:")
IO.inspect(result.caches)
{:error, error} ->
IO.puts("An error occurred while attempting to list caches: #{error.error_code}")
raise error
end
備考
Full example code and imports can be found here
let result = await cacheClient.listCaches()
switch result {
case .success(let success):
print("Successfully fetched list of caches: \(success.caches.map { $0.name })")
case .error(let err):
print("Unable to fetch list of caches: \(err)")
exit(1)
}
備考
Full example code and imports can be found here
final result = await cacheClient.listCaches();
switch (result) {
case ListCachesError():
print("Error listing caches: $result");
case ListCachesSuccess():
print("Successfully listed caches: ${result.cacheNames}");
}
備考
Full example code and imports can be found here
Flush cache
cacheの全データをフラッシュします。
属性:
名前 | 型 | 説明 |
---|---|---|
cacheName | String | フラッシュするcacheの名前。 |
- JavaScript
- Java
- C#
- Rust
const result = await cacheClient.flushCache(cacheName);
switch (result.type) {
case FlushCacheResponse.Success:
console.log(`Cache '${cacheName}' flushed`);
break;
case FlushCacheResponse.Error:
throw new Error(
`An error occurred while attempting to flush cache '${cacheName}': ${result.errorCode()}: ${result.toString()}`
);
}
備考
Full example code and imports can be found here
final CacheFlushResponse response = cacheClient.flushCache("test-cache").join();
if (response instanceof CacheFlushResponse.Success) {
System.out.println("Cache 'test-cache' flushed");
} else if (response instanceof CacheFlushResponse.Error error) {
throw new RuntimeException(
"An error occurred while attempting to flush cache 'test-cache': " + error.getErrorCode(),
error);
}
備考
Full example code and imports can be found here
var result = await cacheClient.FlushCacheAsync("test-cache");
if (result is FlushCacheResponse.Success)
{
Console.WriteLine("Cache 'test-cache' flushed");
}
else if (result is FlushCacheResponse.Error error)
{
throw new Exception($"An error occurred while attempting to flush cache 'test-cache': {error.ErrorCode}: {error}");
}
備考
Full example code and imports can be found here
cache_client.flush_cache(cache_name.to_string()).await?;
println!("Cache {} flushed", cache_name);