SQLite-based on-disk cache for Rust.

Overview

sqlite-cache

crates.io

SQLite-based on-disk cache for Rust.

Usage

let cache = Cache::new(
    CacheConfig::default(),
    rusqlite::Connection::open_in_memory().unwrap(),
).unwrap();
let topic = cache.topic("test-topic").unwrap();
assert!(topic.get("hello").unwrap().is_none());
topic.set("hello", b"world", Duration::from_secs(60))
assert!(&topic.get("hello").unwrap().unwrap().data[..] == b"world");

Locked updates

This library supports locked updates to prevent the thundering herd problem on cache misses. The get_for_update API acquires a per-key lock and returns a KeyUpdater; subsequent get_for_update calls on the same key will block until the previous KeyUpdater is dropped.

let (updater, current_value) = topic.get_for_update("hello").await.unwrap();
let new_value = expensive_computation(current_value).await;
updater.write(new_value, Duration::from_secs(60)).unwrap();

Benchmark

These results are from running benches/cache_benchmark.rs on an Apple M1 processor.

  • mt(4): Per-thread operation latency when running the same task on 4 threads.
lookup - cache size 10000
                        time:   [1.5978 us 1.6051 us 1.6130 us]
lookup mt(4) - cache size 10000
                        time:   [9.7801 us 9.8464 us 9.9329 us]
insert - cache size 10000
                        time:   [4.6316 us 4.6785 us 4.7169 us]
insert mt(4) - cache size 10000
                        time:   [21.195 us 21.420 us 21.614 us]
You might also like...
Using embedded database modeled off SQLite - in Rust
Using embedded database modeled off SQLite - in Rust

Rust-SQLite (SQLRite) Rust-SQLite, aka SQLRite , is a simple embedded database modeled off SQLite, but developed with Rust. The goal is get a better u

Query is a Rust server for your remote SQLite databases and a CLI to manage them.

Query Query is a Rust server for your remote SQLite databases and a CLI to manage them. Table Of Contents Run A Query Server CLI Install Use The Insta

An object-relational in-memory cache, supports queries with an SQL-like query language.

qlcache An object-relational in-memory cache, supports queries with an SQL-like query language. Warning This is a rather low-level library, and only p

Simple and handy btrfs snapshoting tool. Supports unattended snapshots, tracking, restoring, automatic cleanup and more. Backed with SQLite.
Simple and handy btrfs snapshoting tool. Supports unattended snapshots, tracking, restoring, automatic cleanup and more. Backed with SQLite.

Description Simple and handy btrfs snapshoting tool. Supports unattended snapshots, tracking, restoring, automatic cleanup and more. Backed with SQLit

Some bunch of test scripts to generate a SQLite DB with 1B rows in fastest possible way

To find out the fastest way to create an SQLite DB with 1B random rows.

🐸Slippi DB ingests Slippi replays and puts the data into a SQLite database for easier parsing.
🐸Slippi DB ingests Slippi replays and puts the data into a SQLite database for easier parsing.

The primary goal of this project is to make it easier to analyze large amounts of Slippi data. Its end goal is to create something similar to Ballchasing.com but for Melee.

A tool for automated migrations for PostgreSQL, SQLite and MySQL.

Models Models is an implementation for a SQL migration management tool. It supports PostgreSQL, MySQL, and SQLite. Quick Start install the CLI by runn

Interface to SQLite

SQLite The package provides an interface to SQLite. Example Open a connection, create a table, and insert some rows: let connection = sqlite::open(":m

SQLite compiled to WASM with pluggable data storage

wasm-sqlite SQLite compiled to WASM with pluggable data storage. Useful to save SQLite in e.g. Cloudflare Durable Objects (example: https://github.com

Comments
  • Specifying Duration::MAX as TTL leads to addition with overflow panic

    Specifying Duration::MAX as TTL leads to addition with overflow panic

    When attempting to set an entry with the maximum possible TTL, sqlite-cache will panic:

    topic.set("key", value, std::time::Duration::MAX);
    

    I can work around this by using an arbitrary value like 300 days worth. I think the panic should at least be an Err variant so that the program doesn't terminate in surprising situations, such as when setting a TTL based on a max-age cache header returned from some external source.

    opened by wez 3
  • Configure Renovate

    Configure Renovate

    Mend Renovate

    Welcome to Renovate! This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin.

    🚦 To activate Renovate, merge this Pull Request. To disable Renovate, simply close this Pull Request unmerged.


    Detected Package Files

    • Cargo.toml (cargo)
    • .github/workflows/ci.yml (github-actions)

    Configuration

    🔡 Renovate has detected a custom config for this PR. Feel free to ask for help if you have any doubts and would like it reviewed.

    Important: Now that this branch is edited, Renovate can't rebase it from the base branch any more. If you make changes to the base branch that could impact this onboarding PR, please merge them manually.

    What to Expect

    With your current configuration, Renovate will create 7 Pull Requests:

    Update Rust crate futures to 0.3.25
    • Schedule: ["at any time"]
    • Branch name: renovate/rust-futures-monorepo
    • Merge into: main
    • Upgrade futures to 0.3.25
    Update Rust crate tracing to 0.1.37
    • Schedule: ["at any time"]
    • Branch name: renovate/tracing-0.x
    • Merge into: main
    • Upgrade tracing to 0.1.37
    Update Rust crate tracing-test to 0.2.3
    • Schedule: ["at any time"]
    • Branch name: renovate/tracing-test-0.x
    • Merge into: main
    • Upgrade tracing-test to 0.2.3
    Update Rust crate criterion to 0.4
    • Schedule: ["at any time"]
    • Branch name: renovate/criterion-0.x
    • Merge into: main
    • Upgrade criterion to 0.4
    Update Rust crate rusqlite to 0.28
    • Schedule: ["at any time"]
    • Branch name: renovate/rusqlite-0.x
    • Merge into: main
    • Upgrade rusqlite to 0.28
    Update Rust crate tokio to 1.22.0
    • Schedule: ["at any time"]
    • Branch name: renovate/tokio-1.x
    • Merge into: main
    • Upgrade tokio to 1.22.0
    Update actions/checkout action to v3
    • Schedule: ["at any time"]
    • Branch name: renovate/actions-checkout-3.x
    • Merge into: main
    • Upgrade actions/checkout to v3

    🚸 Branch creation will be limited to maximum 2 per hour, so it doesn't swamp any CI resources or spam the project. See docs for prhourlylimit for details.


    ❓ Got questions? Check out Renovate's Docs, particularly the Getting Started section. If you need any further assistance then you can also request help here.


    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
Owner
Heyang Zhou
Working on distributed data infrastructure at Deno. I'm interested in digital systems in general, and their human sides as well.
Heyang Zhou
Provides a Rust-based SQLite extension for using Hypercore as the VFS for your databases.

SQLite and Hypercore A Rust library providing SQLite with an virtual file system to enable Hypercore as a means of storage. Contributing The primary r

Jacky Alciné 14 Dec 5, 2022
A Rust-based comment server using SQLite and an intuitive REST API.

soudan A Rust-based comment server using SQLite and an intuitive REST API. Soudan is built with simplicity and static sites in mind. CLI usage See sou

Elnu 0 Dec 19, 2022
ReefDB is a minimalistic, in-memory and on-disk database management system written in Rust, implementing basic SQL query capabilities and full-text search.

ReefDB ReefDB is a minimalistic, in-memory and on-disk database management system written in Rust, implementing basic SQL query capabilities and full-

Sacha Arbonel 75 Jun 12, 2023
🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, SQLite, and MSSQL.

SQLx ?? The Rust SQL Toolkit Install | Usage | Docs Built with ❤️ by The LaunchBadge team SQLx is an async, pure Rust† SQL crate featuring compile-tim

launchbadge 7.6k Dec 31, 2022
Ergonomic bindings to SQLite for Rust

Rusqlite Rusqlite is an ergonomic wrapper for using SQLite from Rust. It attempts to expose an interface similar to rust-postgres. use rusqlite::{para

Rusqlite 1.9k Jan 5, 2023
SQLite clone from scratch in Rust

Rust-SQLite (SQLRite) Rust-SQLite, aka SQLRite , is a simple embedded database modeled off SQLite, but developed with Rust. The goal is get a better u

João Henrique Machado Silva 952 Jan 5, 2023
ChiselStore is an embeddable, distributed SQLite for Rust, powered by Little Raft.

ChiselStore ChiselStore is an embeddable, distributed SQLite for Rust, powered by Little Raft. SQLite is a fast and compact relational database manage

null 516 Jan 2, 2023
cogo rust coroutine database driver (Mysql,Postgres,Sqlite)

cdbc Coroutine Database driver Connectivity.based on cogo High concurrency,based on coroutine No Future<'q,Output=*>,No async fn, No .await , no Poll*

co-rs 10 Nov 13, 2022
Rusqlite is an ergonomic wrapper for using SQLite from Rust

Rusqlite Rusqlite is an ergonomic wrapper for using SQLite from Rust. It attempts to expose an interface similar to rust-postgres. use rusqlite::{para

Rusqlite 1.9k Jan 7, 2023
Build SQLite virtual file systems (VFS) by implementing a simple Rust trait.

sqlite-vfs Build SQLite virtual file systems (VFS) by implementing a simple Rust trait. Documentation | Example This library is build for my own use-c

Markus Ast 56 Dec 19, 2022