Skip to content

Commit

Permalink
feat: createOrGet -> getOrCreate (#89)
Browse files Browse the repository at this point in the history
implementation does a create followed by Get.This should be updated once metadata sync is sorted out. Then this will be implemented as
```
try {
    return getCache(cacheName);
} catch (CacheNotFoundException e) {
    createCache(cacheName);
    return getCache(cacheName);
}
```
  • Loading branch information
gautamomento authored Oct 13, 2021
1 parent 5317a8d commit d5ae9a4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions momento-sdk/src/intTest/java/momento/sdk/MomentoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void testHappyPath() {
@Test
void recreatingCacheWithSameName_throwsAlreadyExists() {
Momento momento = Momento.builder(authToken).build();
momento.createOrGetCache(cacheName);
momento.getOrCreateCache(cacheName);
assertThrows(CacheAlreadyExistsException.class, () -> momento.createCache(cacheName));
}

Expand All @@ -63,7 +63,7 @@ void testInvalidCacheName() {
Momento.builder(authToken).endpointOverride(DEFAULT_MOMENTO_HOSTED_ZONE_ENDPOINT).build();

assertThrows(InvalidArgumentException.class, () -> momento.createCache(" "));
assertThrows(InvalidArgumentException.class, () -> momento.createOrGetCache(" "));
assertThrows(InvalidArgumentException.class, () -> momento.getOrCreateCache(" "));
}

@Test
Expand All @@ -90,7 +90,7 @@ void deleteForNonExistantCache_throwsNotFound() {
}

private static void runHappyPathTest(Momento momento, String cacheName) {
Cache cache = momento.createOrGetCache(cacheName);
Cache cache = momento.getOrCreateCache(cacheName);

String key = java.util.UUID.randomUUID().toString();

Expand Down
3 changes: 2 additions & 1 deletion momento-sdk/src/main/java/momento/sdk/Momento.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public DeleteCacheResponse deleteCache(String cacheName) {
* @return {@link Cache} client to perform operations against the Momento Cache with the provided
* name.
*/
public Cache createOrGetCache(String cacheName) {
public Cache getOrCreateCache(String cacheName) {
// TODO: Switch this to do a get first followed by Create
checkCacheNameValid(cacheName);
try {
createCache(cacheName);
Expand Down

0 comments on commit d5ae9a4

Please sign in to comment.