All Projects → next-boost → hybrid-disk-cache

next-boost / hybrid-disk-cache

Licence: other
A hybrid disk cache library that utilized both the solid SQLite3 and file system.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to hybrid-disk-cache

disk-lru-cache
💾 Disk LRU cache with persisted journal
Stars: ✭ 21 (+10.53%)
Mutual labels:  file-cache, disk-cache
Swift-FFDB
a Object/Relational Mapping (ORM) support to iOS and MacOS .Since SwiftFFDB is build on top of FMDB.
Stars: ✭ 22 (+15.79%)
Mutual labels:  sqlite3
Better Sqlite3
The fastest and simplest library for SQLite3 in Node.js.
Stars: ✭ 2,778 (+14521.05%)
Mutual labels:  sqlite3
libcache
A caching library that provides an in-memory and file based cache for Ruby
Stars: ✭ 25 (+31.58%)
Mutual labels:  file-cache
Notadd
A microservice development architecture based on nest.js. —— 基于 Nest.js 的微服务开发架构。
Stars: ✭ 2,556 (+13352.63%)
Mutual labels:  sqlite3
sqllex
The most pythonic ORM (for SQLite and PostgreSQL). Seriously, try it out!
Stars: ✭ 80 (+321.05%)
Mutual labels:  sqlite3
Choochoo
Training Diary
Stars: ✭ 186 (+878.95%)
Mutual labels:  sqlite3
SQLiteReverse
腾讯课堂《SQLite数据库逆向分析》
Stars: ✭ 118 (+521.05%)
Mutual labels:  sqlite3
Luki
[Deprecated] The official repository for Luki the Discord bot
Stars: ✭ 21 (+10.53%)
Mutual labels:  sqlite3
cache
🗃 Generic cache use and cache manage. Provide a unified usage API by packaging various commonly used drivers. Support File, Memory, Redis, Memcached and more. Go 通用的缓存使用库,通过包装各种常用的驱动,来提供统一的使用API,便于使用。
Stars: ✭ 146 (+668.42%)
Mutual labels:  file-cache
Mikro Orm
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.
Stars: ✭ 3,874 (+20289.47%)
Mutual labels:  sqlite3
Knex
A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.
Stars: ✭ 15,083 (+79284.21%)
Mutual labels:  sqlite3
HealthApp
A desktop application to fetch Wikipedia,Google,Disease results and save them as text file,in database.Have a Section to search details about doctors in location
Stars: ✭ 23 (+21.05%)
Mutual labels:  sqlite3
React Native Sqlite 2
SQLite3 Native Plugin for React Native for iOS, Android, Windows and macOS.
Stars: ✭ 217 (+1042.11%)
Mutual labels:  sqlite3
xyr
Query any data source using SQL, works with the local filesystem, s3, and more. It should be a very tiny and lightweight alternative to AWS Athena, Presto ... etc.
Stars: ✭ 58 (+205.26%)
Mutual labels:  sqlite3
Pydbgen
Random dataframe and database table generator
Stars: ✭ 191 (+905.26%)
Mutual labels:  sqlite3
Sqleet
SQLite3 encryption that sucks less
Stars: ✭ 244 (+1184.21%)
Mutual labels:  sqlite3
ZXDataHandle
简单易用的数据转换和存储框架,支持一行代码将模型、模型数组、Json字符串、字典互转;支持模型映射到sqlite3数据库,无需书写sql
Stars: ✭ 13 (-31.58%)
Mutual labels:  sqlite3
usqlite
μSQLite library module for MicroPython
Stars: ✭ 52 (+173.68%)
Mutual labels:  sqlite3
sqlite-createtable-parser
A parser for sqlite create table sql statements.
Stars: ✭ 67 (+252.63%)
Mutual labels:  sqlite3

Coverage Status Maintainability

hybrid-disk-cache

A hybrid disk cache library that utilized both the solid SQLite3 database and the file system.

yarn add @next-boost/hybrid-disk-cache

When the value is larger than 10 kilobytes, it will be written to the file system, otherwise saved in SQLite3 database.

The benefits of using this kind of hybrid cache are:

  • Always use the small footprint and high performace SQLite3 index.
  • Using file system for larger files. No need to run vacuum for releasing space

Also, here are some bonus:

  • 100% test coverage
  • Pure Typescript
  • Used in production with 300K keys
  • SQLite3's indices will always be used when searching for a key. (which is FAST)

This hybrid idea is inspired by python-diskcache. We used it in our Python production stack, and it works just as great as what we'd expected.

APIs

// tbd, time before deletion: This is used to control how long a key
// should remain in the cache after expired (ttl)
// And `cache.purge` will delete all records with ttl + tbd < now
const cache = new Cache({ path, ttl, tbd })

// set. if ttl empty, use the cache's ttl
cache.set(key, value)
// set. will expire in 5 seconds
cache.set(key, value, 5)

// get
cache.get(key, defaultValue)

// del
cache.del(key)

// check cache availability and status
// status in 'miss' | 'stale' | 'hit'
const status = cache.has(key)

// if you want to serve even the stale value
if (cache.has(key) !== 'miss') {
    const value = cache.get(key)
}

// if you only want the unexpired one
if (cache.has(key) === 'hit') {
    const value = cache.get(key)
}

// delete all expired keys
cache.purge()

Check index.test.ts for examples.

Benchmarks

With a series of 10B ~ 500KB data writing and reading, here are the results on a Samsung 860 EVO SATA SSD:

Here is the benchmark source code.

> cache located at: /tmp/hdc
> generating bench data from 10B to 500000B
> starting 3000 x 15 writes
  done: 69.34 μs/record.
> starting 3000 x 15 reads
  done: 26.65 μs/record.

License

MIT. Copyright 2020, Rakuraku Jyo.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].