Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
2 parents 0746bca + a63c4bb commit efe8b25
Show file tree
Hide file tree
Showing 43 changed files with 399 additions and 304 deletions.
16 changes: 8 additions & 8 deletions examples/cloudflare-workers/web-sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/cloudflare-workers/web-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"dependencies": {
"@gomomento/sdk-core": "^1.40.0",
"@gomomento/sdk-web": "^1.70.0",
"@gomomento/sdk-web": "^1.70.1",
"xhr4sw": "^0.0.5"
}
}
30 changes: 15 additions & 15 deletions examples/nodejs/access-control/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/nodejs/access-control/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"typescript": "4.4.3"
},
"dependencies": {
"@gomomento/sdk": "^1.70.0"
"@gomomento/sdk": "^1.70.1"
}
}
30 changes: 15 additions & 15 deletions examples/nodejs/aws/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/nodejs/aws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
},
"dependencies": {
"@aws-sdk/client-secrets-manager": "^3.370.0",
"@gomomento/sdk": "^1.70.0"
"@gomomento/sdk": "^1.70.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ async function main() {
}),
defaultTtlSeconds: 60,
});
await cacheClient.createCache('test-cache');

await example_configuration_ConstructWithNoConfig();
await example_configuration_ConstructWithLambdaConfig();
Expand Down
94 changes: 94 additions & 0 deletions examples/nodejs/cache/doc-example-files/doc-examples-js-apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ import {
CacheIncrement,
CacheItemGetType,
CacheSetIfNotExists,
CacheSetIfPresent,
CacheSetIfAbsent,
CacheSetIfEqual,
CacheSetIfNotEqual,
CacheSetIfPresentAndNotEqual,
CacheSetIfAbsentOrEqual,
CacheListFetch,
CacheListConcatenateBack,
CacheListConcatenateFront,
Expand Down Expand Up @@ -283,6 +289,88 @@ async function example_API_SetIfNotExists(cacheClient: CacheClient, cacheName: s
}
}

async function example_API_SetIfPresent(cacheClient: CacheClient, cacheName: string) {
const result = await cacheClient.setIfPresent(cacheName, 'test-key', 'test-field');
if (result instanceof CacheSetIfPresent.Stored) {
console.log("Field 'test-field' set in key 'test-key'");
} else if (result instanceof CacheSetIfPresent.NotStored) {
console.log(`Key 'test-key' does not exist in cache ${cacheName}, so we did not set the field`);
} else if (result instanceof CacheSetIfPresent.Error) {
throw new Error(
`An error occurred while attempting to call setIfPresent for the key 'test-key' in cache cacheName: ${result.errorCode()}: ${result.toString()}`
);
}
}

async function example_API_SetIfAbsent(cacheClient: CacheClient, cacheName: string) {
const result = await cacheClient.setIfAbsent(cacheName, 'test-key', 'test-field');
if (result instanceof CacheSetIfAbsent.Stored) {
console.log("Field 'test-field' set in key 'test-key'");
} else if (result instanceof CacheSetIfAbsent.NotStored) {
console.log(`Key 'test-key' already exists in cache ${cacheName}, so we did not overwrite it`);
} else if (result instanceof CacheSetIfAbsent.Error) {
throw new Error(
`An error occurred while attempting to call setIfAbsent for the key 'test-key' in cache cacheName: ${result.errorCode()}: ${result.toString()}`
);
}
}

async function example_API_SetIfEqual(cacheClient: CacheClient, cacheName: string) {
const result = await cacheClient.setIfEqual(cacheName, 'test-key', 'test-field', 'value-to-check');
if (result instanceof CacheSetIfEqual.Stored) {
console.log("Field 'test-field' set in key 'test-key'");
} else if (result instanceof CacheSetIfEqual.NotStored) {
console.log("Value of key 'test-key' does not equal 'value-to-check', so we did not set the field");
} else if (result instanceof CacheSetIfEqual.Error) {
throw new Error(
`An error occurred while attempting to call setIfEqual for the key 'test-key' in cache cacheName: ${result.errorCode()}: ${result.toString()}`
);
}
}

async function example_API_SetIfNotEqual(cacheClient: CacheClient, cacheName: string) {
const result = await cacheClient.setIfNotEqual(cacheName, 'test-key', 'test-field', 'value-to-check');
if (result instanceof CacheSetIfNotEqual.Stored) {
console.log("Field 'test-field' set in key 'test-key'");
} else if (result instanceof CacheSetIfNotEqual.NotStored) {
console.log("Value of key 'test-key' equals 'value-to-check', so we did not set the field");
} else if (result instanceof CacheSetIfNotEqual.Error) {
throw new Error(
`An error occurred while attempting to call setIfNotEqual for the key 'test-key' in cache cacheName: ${result.errorCode()}: ${result.toString()}`
);
}
}

async function example_API_SetIfPresentAndNotEqual(cacheClient: CacheClient, cacheName: string) {
const result = await cacheClient.setIfPresentAndNotEqual(cacheName, 'test-key', 'test-field', 'value-to-check');
if (result instanceof CacheSetIfPresentAndNotEqual.Stored) {
console.log("Field 'test-field' set in key 'test-key'");
} else if (result instanceof CacheSetIfPresentAndNotEqual.NotStored) {
console.log(
`Key 'test-key' does not exist in cache ${cacheName} or equals 'value-to-check', so we did not set the field`
);
} else if (result instanceof CacheSetIfPresentAndNotEqual.Error) {
throw new Error(
`An error occurred while attempting to call setIfPresentAndNotEqual for the key 'test-key' in cache cacheName: ${result.errorCode()}: ${result.toString()}`
);
}
}

async function example_API_SetIfAbsentOrEqual(cacheClient: CacheClient, cacheName: string) {
const result = await cacheClient.setIfAbsentOrEqual(cacheName, 'test-key', 'test-field', 'value-to-check');
if (result instanceof CacheSetIfAbsentOrEqual.Stored) {
console.log("Field 'test-field' set in key 'test-key'");
} else if (result instanceof CacheSetIfAbsentOrEqual.NotStored) {
console.log(
`Key 'test-key' exists in cache ${cacheName} and is not equal to 'value-to-check', so we did not set the field`
);
} else if (result instanceof CacheSetIfAbsentOrEqual.Error) {
throw new Error(
`An error occurred while attempting to call setIfAbsentOrEqual for the key 'test-key' in cache cacheName: ${result.errorCode()}: ${result.toString()}`
);
}
}

async function example_API_SetBatch(cacheClient: CacheClient, cacheName: string) {
const values = new Map<string, string>([
['abc', '123'],
Expand Down Expand Up @@ -1420,6 +1508,12 @@ async function main() {
await example_API_Increment(cacheClient, cacheName);
await example_API_ItemGetType(cacheClient, cacheName);
await example_API_SetIfNotExists(cacheClient, cacheName);
await example_API_SetIfAbsent(cacheClient, cacheName);
await example_API_SetIfPresent(cacheClient, cacheName);
await example_API_SetIfEqual(cacheClient, cacheName);
await example_API_SetIfNotEqual(cacheClient, cacheName);
await example_API_SetIfPresentAndNotEqual(cacheClient, cacheName);
await example_API_SetIfAbsentOrEqual(cacheClient, cacheName);
await example_API_SetBatch(cacheClient, cacheName);
await example_API_GetBatch(cacheClient, cacheName);

Expand Down
30 changes: 15 additions & 15 deletions examples/nodejs/cache/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit efe8b25

Please sign in to comment.