
Research
/Security News
Shai Hulud Strikes Again (v2)
Another wave of Shai-Hulud campaign has hit npm with more than 500 packages and 700+ versions affected.
@agoric/cache
Advanced tools
This cache mechanism allows a cache client function to synchronize with a cache backend. Any passable object can be a cache key or a cache value.
import { makeCache, makeScalarStoreCoordinator } from '@agoric/cache';
import { M } from '@agoric/store';
import { makeScalarBigMapStore } from '@agoric/vat-data';
const store = makeScalarBigMapStore('cache');
const coordinator = makeScalarStoreCoordinator(store);
const cache = makeCache(coordinator);
// Direct value manipulation.
await cache('baz'); // undefined
await cache('baz', 'barbosa'); // 'barbosa'
// Match-and-set.
await cache('baz', 'babaloo', undefined); // 'barbosa'
await cache('baz', 'babaloo', 'barbosa'); // 'babaloo'
// One-time initialization.
await cache('frotz', 'default'); // 'default'
await cache('frotz', 'ignored'); // 'default'
// Update the `'foo'` entry, using its old value (initially `undefined`).
await cache('foo'); // `undefined`
const updater = (oldValue = 'bar') => `${oldValue}1`;
await cache('foo', updater, M.any()); // 'bar1'
await cache('foo', updater, M.any()); // 'bar11'
await cache('foo'); // 'bar11'
// You can also specify a guard pattern for the value to update. If it
// doesn't match the latest value, then the cache isn't updated.
await cache('foo', updater, 'nomatch'); // 'bar11'
await cache('foo', updater, 'bar11'); // 'bar111'
await cache('foo', updater, 'bar11'); // 'bar111'
await cache('foo'); // 'bar111'
The client-side API is normally exposed as a single function named cache. You
can create a cache client function by running makeCache(coordinator, follower). If not specified, the default coordinator is just a local in-memory
map without persistence.
undefined. It is impossible to distinguish a set value of undefined from an unset keycache(key, (oldValue) => ERef<newValue>, guardPattern?): Promise<newValue> -
transactionally updates the value of key from a value matched by guardPattern
to the results of sanitizing the result of calling the updater function with
that value. Retries all three steps (read current value, attempt match, call updater),
if the transaction is stale. guardPattern defaults to matching only undefined.
Returns the current value after any resulting update.cache(key, passable, guardPattern?): Promise<newValue> -
same as above with an updater function that ignores arguments and returns
passable (e.g., () => passable).The cache coordinator must implement the Coordinator interface, which supports
eventual consistency with optimistic updates:
interface Updater {
/**
* Calculate the newValue for a given oldValue
*/
update: (oldValue: Passable) => unknown
}
interface Coordinator {
/**
* Read an eventually-consistent value for the specified key.
*/
getRecentValue: (key: Passable) => Promise<Passable>,
/**
* Update a cache value to newValue, but only if guardPattern matches the current value.
*/
setCacheValue: (key: Passable, newValue: Passable, guardPattern: Pattern) => Promise<Passable>,
/**
* Update a cache value via an updater calculation of newValue, but only if guardPattern
* matches the current value.
*/
updateCacheValue: (key: Passable, updater: ERef<Updater>, assertedMatch: Matcher) => Promise<Passable>,
}
FAQs
Agoric's simple cache interface
The npm package @agoric/cache receives a total of 2,064 weekly downloads. As such, @agoric/cache popularity was classified as popular.
We found that @agoric/cache demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 10 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Another wave of Shai-Hulud campaign has hit npm with more than 500 packages and 700+ versions affected.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.