howdy/cache/database
A cache store in a Gloo Repo, on PostgreSQL or SQLite, through
howdy/database. Every node using the same database shares the
entries and their invalidations.
import howdy/cache
import howdy/cache/database as cache_database
let assert Ok(Nil) = migration.run(db, [cache_database.schema()])
let assert Ok(store) = cache_database.store(db)
let app_cache = cache.new(store)
Reading an entry is one query, so this store pays off for work that
costs more than a query: several joined queries, a call to another
service, rendering a large page. On PostgreSQL the entry tables are
UNLOGGED: writes skip the write-ahead log, and a crash empties them,
which for a cache is only a cold start.
Expired entries are deleted every five minutes by a process that lives
as long as the process that called store, so call it in main.
invalidate also deletes the entries carrying the tags. The table of
tag versions keeps one row per tag ever invalidated; it has to, since
forgetting a version could make an old entry current again.
Values
pub fn schema() -> migration.Package
The howdy_cache_ tables. Run with howdy/migration during deployment.
pub fn store(
repo: repo.Repo,
) -> Result(cache.Store, service.Error)
A store over this Repo, once its schema is checked, with a process deleting expired entries every five minutes. The process stops when the caller exits.
pub fn sweep(repo: repo.Repo) -> Result(Int, service.Error)
Delete expired entries, a thousand at a time, and return how many went.