
Security News
npm ‘is’ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
bun-sqlite-cache
Advanced tools
Bun SQLite cache is a Bun-ified version of [jkelin](https://github.com/jkelin)'s [sqlite-lru-cache](https://github.com/jkelin/cache-sqlite-lru-ttl) (with TTL). Bun's lightning-fast implementation makes this perfect for a quick in-memory caching solution w
Bun SQLite cache is a Bun-ified version of jkelin's sqlite-lru-cache (with TTL). Bun's lightning-fast implementation makes this perfect for a quick in-memory caching solution with TTL support.
bun add bun-sqlite-cache
Using this cache is dead simple: simply create a new BunSQLiteCache instance and you're set
import { BunSQLiteCache } from "bun-sqlite-cache";
const cache = new BunSQLiteCache();
cache.set("foo", { bar: "baz", waldo: [4, 3, 2, 8] });
const value = cache.get("foo");
console.log(value) // { bar: "baz", waldo: [4, 3, 2, 8] }
import { BunSQLiteCache, BunSQLiteCacheConfiguration } from "bun-sqlite-cache";
// the given values are the defaults
const options: BunSQLiteCacheConfiguration = {
database: ":memory:", // database file or in memory: default :- in memory sqlite table
defaultTtlMs: undefined, // the default time it takes (in ms) for a cached row to expire: default :- no expiry
maxItems: undefined, // max number of items allowed in cache. if number of items is exceeded then LRU eviction policy is used: default :- no limit
compress: false // whether to compress data before putting it in the cache (uses Bun's synchronous gzip)
}
const cache = new BunSQLiteCache(options)
set(key: string, value: any, opts?: { ttlMs?: number, compress?: boolean }): boolean
Adds a value to the cache by serializing the given value and adding it to the table
key
: the key to store the value undervalue
: the value to store - can be anything serializable by 'v8'ttlMs
: the time it takes (in ms) for a cached row to expire: default:- no expirycompress
: whether to compress data before putting it in the cache (uses Bun's synchronous gzip)boolean
dictating whether the value was successfully added to the cacheget(key: string, withMeta?: boolean): any | ValueWithMeta<T> | undefined
Gets a value from the cache by deserializing the value stored under the given key
key
: the key to get the value fromwithMeta
: whether to return the value with its metadata (i.e. compressed
and key
): default:- false
withMeta
is true
, the return value will be of type ValueWithMeta<T>
: { value: any, compressed: boolean, key: string }
any
)delete(key: string): void
Deletes a value from the cache
key
: the key to delete the value fromclear(): void
Clears the cache
Contributions are welcome - this is my first package so it's probably riddled with stuff that could be improved. Feel free to open an issue or submit a pull request.
MIT
FAQs
Bun SQLite cache is a Bun-ified version of [jkelin](https://github.com/jkelin)'s [sqlite-lru-cache](https://github.com/jkelin/cache-sqlite-lru-ttl) (with TTL). Bun's lightning-fast implementation makes this perfect for a quick in-memory caching solution w
The npm package bun-sqlite-cache receives a total of 11 weekly downloads. As such, bun-sqlite-cache popularity was classified as not popular.
We found that bun-sqlite-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.