Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
2
xkonti avatar

Changes in version 18

Added exists(key): Promise<Boolean> Checks if the provided key exists (has value) in the cache. If the key is expired, it's considered non-existent.

// Check if the key is present in the cache const hasLuckyNumber: Boolean = await exists("luckyNumber");
pomdtr avatar

small feedback about the CACHE_TABLE_NAME setup steps.

I feel like it would a better pattern to initialize your app by creating a val with the following content

import { createCache } from "https://esm.town/v/xkonti/cache?v=18" // all the function are exported here export const cache = createCache({ tableName: "my-table-name" })

The main benefit is that it allows me to create as much cache as I want, and allow me to easily upgrade to a new version by just changing the query param.

Updated: June 1, 2024