@izara_project/izara-core-library-stored-cache
v1.0.8
Published
Shared stored cache logic
Readme
izara-core-library-stored-cache
update version
- commit code first npm version patch || npm version minor || npm version major
can also push to repo ..
git push
make sure commits look correct
push to npm
npm publish
update project that uses this package
npm update @izara_project/izara-core-library-stored-cache
StoredCache SharedLib Usage
This document describes how to use the storedCacheSharedLib library for managing cache status and related data in DynamoDB tables.
Features
- Check cache status in a DynamoDB table.
- Mark cache records as complete.
- Optionally delete related data tables when completing cache, based on
uniqueRequestId.
Usage Examples
1. Check Stored Cache Status
Checks the status of a cache record in the cacheMain table.
let [cacheStatus, cacheMain] = await storedCacheSharedLib.checkStoredCacheStatus(
_izContext,
"cacheMain", // DynamoDB table name
{ idKey: "001002003" }, // Key values
{ settings: {} }, // Additional attributes when creating
'testStoredCache', // Prefix
[], // Attributes to remove
[], // Data tables to delete on expired
[], // Errors found
uniqueRequestId, // Overwrite unique request ID
false, // Do not create if not exists
null, // Overwrite expiry interval
false // Overwrite existing cache
);Behavior:
- If no record exists, returns
process. - If a record exists and is not expired, returns
processing. - If a record exists but is expired, returns
process. - If status is
completeorerror, returns the corresponding cache status.
Notes
If you set
deleteDataTableOnExpired, records in the data table will be deleted when the cache expires.If
overwriteExistingCache === true, the function behaves as if the cache is expired and will overwrite the existing cache.format of data tables to delete on expired
[
{
tableName: 'TableData',
partitionKeyFieldName: 'cacheId',
sortKeyFieldName: 'sortCacheId',
dataPartitionKeyTemplate: "[cacheId]",
}
]2. Complete Stored Cache
Sets the status of a cache record to complete if it is not already complete or error.
await storedCacheSharedLib.completeStoredCache(
_izContext,
"cacheMain",
{ idKey: "001002003" }, // Key values
"complete", // Status
{}, // Additional attributes
"testStoredCache", // Prefix
null, // Expiry interval
Date.now(), // Time cache completed
[] // Errors found
);3. Complete Stored Cache and Delete Related Data
Completes the cache record and deletes related data tables if uniqueRequestId does not match.
await storedCacheSharedLib.completeStoredCache(
_izContext,
"cacheMain",
{ idKey: "001002003" }, // Key values
"complete", // Status
{
settings: {
deleteDataTable: [ // deleteDataTable
{
tableName: 'TableData',
partitionKeyFieldName: 'cacheId',
sortKeyFieldName: 'sortCacheId',
dataPartitionKeyTemplate: "[cacheId]",
uniqueRequestIdFieldName: "xx", // optional, need to add this when complete storedCache and need to check uniqueRequestId
}
],
uniqueRequestId: uniqueRequestId
}
},
"testStoredCache", // Prefix
null, // Expiry interval
Date.now(), // Time cache completed
[] // Errors found
);Behavior:
- If
uniqueRequestIddoes not match, the function checks the main cache record and deletes data records with the same partition key but differentuniqueRequestId. - should set deleteDataTable and uniqueRequestId
Behavior:
