Skip to main content

Crate grabcli_sqlite

Crate grabcli_sqlite 

Source
Expand description

SQLite cache backend for grabcli: SqliteCache implements grabcli_core::cache::Cache with one database at <root>/cache.sqlite (WAL, mode 0600, inside a 0700 directory):

  • Responses (entries): raw upstream JSON by key hash.
  • Catalog (catalog): restaurants, where they were seen from, menu categories and items, with FTS5 word + trigram indexes.
  • Images (images): content-addressed files under <root>/images/, indexed in SQLite and evicted LRU by total size.

The database is opened lazily on first use; if it can’t be opened every call errors, which CacheHandle treats as a miss. Housekeeping (stats, clear, prune) is only on this type, for grab cache. Schema migrations live in db.rs: append to MIGRATIONS, never edit a shipped one.

§Example: configure a cache

use grabcli_core::cache::CacheConfig;
use grabcli_sqlite::SqliteCache;

let cache = SqliteCache::new("/path/to/private/cache", CacheConfig::default());
let stats = cache.stats()?;
println!("cached responses: {}", stats.entries);

The first operation opens or creates the database. Give each application its own private cache directory. Pass an Arc<SqliteCache> as the core Cache implementation when creating a context.

Modules§

catalog
The normalized catalog: restaurants/stores, where they were seen from, menu categories and menu items, with FTS5 indexes for offline search.
images
Content-addressed image store: <cache dir>/images/ab/cd/<sha256>.<ext> (files 0600, dirs 0700), indexed in the images table by URL. Several URLs with identical bytes share one file. When the total size of distinct files exceeds [cache] image_max_mb (default 500), the least recently used files are evicted.

Structs§

CacheStats
grab cache stats.
ClearReport
What grab cache clear --all removed.
ImageStats
Image store numbers in CacheStats.
KindStats
Per-kind numbers in CacheStats.
PruneReport
What grab cache prune removed.
SqliteCache
The SQLite cache. Cheap to clone (clones share one connection).

Constants§

DB_FILE
The database file name inside the cache dir.