npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bun-sqlite-cache

v1.2.0

Published

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

Downloads

30

Readme

Bun SQLite Cache

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.

Installation

bun add bun-sqlite-cache

Usage

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] }

Methods

Initialize

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 under
  • value: the value to store - can be anything serializable by 'v8'
  • opts:
    • ttlMs: the time it takes (in ms) for a cached row to expire: default:- no expiry
    • compress: whether to compress data before putting it in the cache (uses Bun's synchronous gzip)
  • returns: boolean dictating whether the value was successfully added to the cache

get(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 from
  • withMeta: whether to return the value with its metadata (i.e. compressed and key): default:- false
    • if withMeta is true, the return value will be of type ValueWithMeta<T>: { value: any, compressed: boolean, key: string }
  • returns: Deserialized value stored under the given key (any)

delete(key: string): void

Deletes a value from the cache

  • key: the key to delete the value from
  • returns: void

clear(): void

Clears the cache

  • returns: void

Contributing

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.

License

MIT