Check cached sources with upstream after the cache TTL (closes #69)
check / check (push) Waiting to run
check / check (push) Waiting to run
Cached images were served until eviction, so upstream changes were missed. After 24 hours a request checks the source with upstream, sending its stored ETag and Last-Modified. A 304 renews it with no download or conversion. New bytes replace it; older variants are converted again. A failed check serves the cached image and puts the URL in the negative cache. Images not checked for 30 days are evicted. Variant rows keep the source's ETag and Last-Modified for checking a variant of an evicted source. A variant file's modification time is its source's check time when it was made or renewed. Hits read it without a database call. The ETag includes it, so new bytes get a new ETag. Model: opus-5-5
This commit is contained in:
1 parent
1379497897
commit
bfe3861314
28 files changed
+1689
-269
No files matched your search
@@ -3,14 +3,24 @@
|
||||
|
||||
-- Source images, one row per source URL
|
||||
-- Files stored at: cache/sources/<ab>/<cd>/<source_key>, where source_key
|
||||
-- is the SHA-256 of the source's host, path and query
|
||||
-- is the SHA-256 of the source's host, path and query.
|
||||
-- fetched_at is when the cached bytes were fetched. checked_at is when
|
||||
-- upstream last sent them or answered that they had not changed.
|
||||
-- upstream_etag and upstream_last_modified are the ETag and Last-Modified
|
||||
-- headers upstream sent with the bytes, or '' when it sent none.
|
||||
CREATE TABLE IF NOT EXISTS source_content (
|
||||
source_key TEXT PRIMARY KEY,
|
||||
size_bytes INTEGER NOT NULL,
|
||||
last_accessed_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
last_accessed_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
fetched_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
checked_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
upstream_etag TEXT NOT NULL DEFAULT '',
|
||||
upstream_last_modified TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_source_content_last_accessed
|
||||
ON source_content(last_accessed_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_source_content_checked
|
||||
ON source_content(checked_at);
|
||||
|
||||
-- Processed variant blobs
|
||||
-- Files stored at: cache/variants/<ab>/<cd>/<cache_key>. Tracked here
|
||||
@@ -18,14 +28,24 @@ CREATE INDEX IF NOT EXISTS idx_source_content_last_accessed
|
||||
-- without a directory scan, and so LRU eviction has a timestamp to order
|
||||
-- on. A cache hit does not read this table: it takes the content type
|
||||
-- from the file's first bytes, and its last_accessed_at is written
|
||||
-- later, in a batch.
|
||||
-- later, in a batch. checked_at is the checked_at of the source the
|
||||
-- variant was made from, when it was made or last renewed; the variant
|
||||
-- file's modification time holds the same time for cache hits.
|
||||
-- upstream_etag and upstream_last_modified are those of the source bytes
|
||||
-- the variant was made from, so the variant can still be checked with
|
||||
-- upstream after its source is evicted.
|
||||
CREATE TABLE IF NOT EXISTS variant_content (
|
||||
cache_key TEXT PRIMARY KEY,
|
||||
size_bytes INTEGER NOT NULL,
|
||||
last_accessed_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
last_accessed_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
checked_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
upstream_etag TEXT NOT NULL DEFAULT '',
|
||||
upstream_last_modified TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_variant_content_last_accessed
|
||||
ON variant_content(last_accessed_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_variant_content_checked
|
||||
ON variant_content(checked_at);
|
||||
|
||||
-- Total cache usage: the sum of size_bytes over source_content and
|
||||
-- variant_content, kept by the triggers below in the same statement
|
||||
|
||||
Reference in new issue
Block a user