🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@arcjet/cache

Package Overview
Dependencies
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arcjet/cache - npm Package Compare versions

Comparing version
1.0.0-beta.10
to
1.0.0-beta.11
+32
-13
index.d.ts

@@ -0,21 +1,31 @@

/**
* Interface for a cache.
*/
export interface Cache<T = unknown> {
/**
* Attempts to retrieve a value from the cache. If a value exists, it will be
* returned with the remaining time-to-live (in seconds).
* Retrieve a value from the cache;
* it will be returned with the remaining time-to-live (in seconds) if it exists.
*
* @param namespace A isolated segement of the cache where keys are tracked.
* @param key The identifier used to retrieve the value.
* @returns A promise for a 2-element tuple containing the value and TTL in
* seconds. If no value is retrieved, the value will be `undefined` and the
* TTL will be `0`.
* @param namespace
* Isolated segment of the cache where keys are tracked.
* @param key
* Key.
* @returns
* Promise for a tuple with the value and TTL in seconds;
* value will be `undefined` and TTL will be `0` if not found.
*/
get(namespace: string, key: string): Promise<[T | undefined, number]>;
/**
* If the cache implementation supports storing values, `set` makes a best
* attempt at storing the value provided until the time-to-live specified.
* Store a value in the cache.
*
* @param namespace A isolated segement of the cache where keys are tracked.
* @param key The identifier used to store the value.
* @param value The value to be stored under the key.
* @param ttl The amount of seconds the value stays valid in the cache.
* @param namespace
* Isolated segment of the cache where keys are tracked.
* @param key
* Key.
* @param value
* Value.
* @param ttl
* Number of seconds the entry stays valid.
* @returns
* Nothing.
*/

@@ -31,4 +41,13 @@ set(namespace: string, key: string, value: T, ttl: number): void;

}
/**
* In-memory cache.
*/
export declare class MemoryCache<T> implements Cache<T> {
/**
* Data.
*/
namespaces: Map<string, Bucket<T>>;
/**
* Create a new in-memory cache.
*/
constructor();

@@ -35,0 +54,0 @@ get(namespace: string, key: string): Promise<[T | undefined, number]>;

@@ -31,4 +31,13 @@ function nowInSeconds() {

}
/**
* In-memory cache.
*/
class MemoryCache {
/**
* Data.
*/
namespaces;
/**
* Create a new in-memory cache.
*/
constructor() {

@@ -35,0 +44,0 @@ this.namespaces = new Map();

{
"name": "@arcjet/cache",
"version": "1.0.0-beta.10",
"version": "1.0.0-beta.11",
"description": "Arcjet cache interface and implementations",

@@ -47,7 +47,6 @@ "keywords": [

"devDependencies": {
"@arcjet/eslint-config": "1.0.0-beta.10",
"@arcjet/rollup-config": "1.0.0-beta.10",
"@arcjet/tsconfig": "1.0.0-beta.10",
"@rollup/wasm-node": "4.46.2",
"eslint": "9.32.0",
"@arcjet/eslint-config": "1.0.0-beta.11",
"@arcjet/rollup-config": "1.0.0-beta.11",
"@rollup/wasm-node": "4.50.0",
"eslint": "9.34.0",
"typescript": "5.9.2"

@@ -54,0 +53,0 @@ },