@zcatalyst/cache
v0.0.3
Published
JavaScript SDK for Catalyst Cache
Maintainers
Readme
@zcatalyst/cache
JavaScript SDK for Catalyst Cache
Overview
The @zcatalyst/cache package provides JavaScript/TypeScript methods to interact with Catalyst Cache. It exposes Cache and Segment APIs for segment lookup and cache key operations. Runs in Node.js (server-side) environments only.
Prerequisites
- A Catalyst project set up
- Cache segments created in your project
- Understanding of cache concepts and architecture
Installation
To install this package, simply type add or install @zcatalyst/cache using your favorite package manager:
npm install @zcatalyst/cacheyarn add @zcatalyst/cachepnpm add @zcatalyst/cache
Getting Started
Import
The Catalyst SDK is modularized by Components.
To send a request, you only need to import the Cache:
// ES5 example
const { Cache } = require('@zcatalyst/cache');// ES6+ example
import { Cache } from '@zcatalyst/cache';Usage
To send a request, you:
- Create a Cache Instance.
- Call the Cache operation with input parameters.
const cache = new Cache();
// Get a segment instance (no await needed)
const segment = cache.segment('segment-id');
// Or get segment details (requires await)
const segmentDetails = await cache.getSegmentDetails('segment-id');Async/await
We recommend using await operator to wait for the promise returned by send operation as follows:
try {
const segment = cache.segment('segment-id');
const data = await segment.getValue('Age');
// process data.
} catch (error) {
// error handling.
} finally {
// finally.
}Error Handling
try {
const data = await segment.getValue('Age');
// process data.
} catch (error) {
const message = error.message;
const status = error.statusCode;
console.log({ message, status });
}Resources
- Catalyst Cache Documentation
- Cache Key Concepts
- Cache Architecture
- Cache Segments
- Cache SDK Reference
- SDK Documentation
Contributing
See CONTRIBUTING for more information on how to get started.
License
This SDK is distributed under the Apache License 2.0. See LICENSE file for more information.
