
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@solid-soda/cache
Advanced tools
It provides features covering simple to advanced caching needs. It is designed for performance and resiliency, ships with ready to use providers for the most common caching backends.
It provides features covering simple to advanced caching needs. It is designed for performance and resiliency, ships with ready to use providers for the most common caching backends.
yarn add @solid-soda/cache
In example app we want to redis as cache-backend. Just create a simple cache instance:
import { Cache, RedisProvider } from "@solid-soda/cache";
const provider = new RedisProvider({
host: "localhost",
port: 6379,
password: "password",
});
export const cache = new Cache(provider);
That is all. We can use cache in any place of our application, or pass the result to DI container, etc.
import { cache } from "./cache";
// ...
let item = await cache.get("my-key");
if (!item) {
// cache for key "my-key" not found
item = doHardWork();
await cache.set("my-key", item);
}
Cache#set method has third argument lifetime (amount of mimilliseconds). You can pass it, and after this time cached item will be invalidate.
It's a very simple mechanism:
import { Cache, InMemoryProvider } from "@solid-soda/cache";
const provider = new InMemoryProvider();
const cache = new Cache(provider);
// ...
async function doDeal() {
await cache.set("key", "cached!", 1000);
await sleep(600);
const value1 = await cache.get("key"); // 'cached!'
await sleep(600);
const value2 = await cache.get("key"); // null
}
Will be released later
You can use many cache providers in your application.
import { Cache, InMemoryProvider } from "@solid-soda/cache";
const provider = new InMemoryProvider();
export const cache = new Cache(provider);
import { Cache, RedisProvider } from "@solid-soda/cache";
const provider = new RedisProvider({
host: "localhost",
port: 6379,
password: "password",
});
export const cache = new Cache(provider);
If you want to use custom serializer, just pass it as second argument to RedisProvider constructor. More about serializers.
import { Cache, RedisProvider } from "@solid-soda/cache";
const provider = new RedisProvider(credentials, serializer);
export const cache = new Cache(provider);
import { Cache, FileSystemProvider } from "@solid-soda/cache";
const provider = new FileSystemProvider({
baseDir: __dirname,
});
export const cache = new Cache(provider);
If you don't pass baseDir it will be use os.tmpdir.
If you want to use custom serializer, just pass it to config in FileSystemProvider constructor. More about serializers.
import { Cache, FileSystemProvider } from "@solid-soda/cache";
const provider = new FileSystemProvider({ baseDir: __dirname, serializer });
export const cache = new Cache(provider);
This provider allow you to use any numbers of providers, it'll spread values to all providers.
import {
Cache,
MultipleProvidersProvider,
RedisProvider,
InMemoryProvider,
} from "@solid-soda/cache";
const provider = new MultipleProvidersProvider([
new RedisProvider({
host: "redis-1",
port: 6379,
}),
new RedisProvider({
host: "redis-2",
port: 6379,
}),
]);
export const cache = new Cache(provider);
Common use case: cache is really large and application need more than one Redis to store it.
This library can includes only limited number of providers, but you can create custom provider and use it for cache. Just implement CacheProvider intreface.
interface CacheProvider {
get<T>(key: string, def?: T): Promise<T | undefined>;
set<T>(key: string, value: T): Promise<void>;
reset(key: string): Promise<void>;
}
For example, we can create CustomMemoryProvider:
import { CacheProvider } from "@solid-soda/cache";
export class CustomMemoryProvider implements CacheProvider {
private readonly cache = {};
get = async (key, def) => this.cache[key] || def;
set = async (key, value) => {
this.cache[key] = value;
};
reset = async (key) => {
this.cache[key] = undefined;
};
}
Brilliant! Create the provider instance and pass in to Cache.
If can provider stores only string value, you can pass serializer to it. If you don't, provider will use default serializer based on JSON.parse and JSON.stringify.
Any serizliser must implements Serializer interface:
interface Serializer {
serialize<T>(value: T): Promise<string>;
deserialize<T>(value: string): Promise<T>;
}
Custom serializer example:
import { Serializer } from '@solid-soda/cache'
const fastSerizliser: Serializer = {
async serialize(value) {
const str = // do something
return str
},
async deserialize(str) {
const value = // do something
return value
},
}
FAQs
It provides features covering simple to advanced caching needs. It is designed for performance and resiliency, ships with ready to use providers for the most common caching backends.
We found that @solid-soda/cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.