1 Commits
Author SHA1 Message Date
clawbot 77907e5b05 Remove the unused cache lifetime setting (closes #69)
check / check (push) Canceled after 0s
CacheConfig.CacheTTL was set to DefaultCacheTTL (24 hours) and never
read, so cached images never expired. Remove the field, the constant
and the line that set it. Cached source and transformed images stay
until eviction removes them to keep the cache within cache_max_bytes.

A new test caches a source and a transformed image, sets back two days
fetched_at in source_metadata, fetched_at and last_accessed_at in
source_content, created_at and last_accessed_at in variant_content, the
fetched_at in the source's metadata file, the created_at in the .meta
file, and the access and modification times of those two files and of
the two image files, and checks that both are still served from the
cache without a new upstream fetch.

Existing tests lose only the CacheTTL line of their cache config.

Model: opus-5-5
2026-10-13 04:49:33 +00:00
+16 -14
View File
@@ -434,21 +434,21 @@ func TestService_Get_Caching(t *testing.T) {
// TestService_Get_ServesSourceAndVariantCachedTwoDaysAgo caches a source and // TestService_Get_ServesSourceAndVariantCachedTwoDaysAgo caches a source and
// a variant of it and sets back two days every time pixa stored for them. // a variant of it and sets back two days every time pixa stored for them.
// For the source: fetched_at in source_metadata and in source_content, the // For the source: fetched_at in source_metadata, fetched_at and
// fetched_at in its metadata file, and the access and modification times of // last_accessed_at in source_content, the fetched_at in its metadata file,
// its file and of its metadata file. For the variant: created_at in // and the access and modification times of its file and of its metadata
// variant_content, the created_at in its .meta file, and the access and // file. For the variant: created_at and last_accessed_at in variant_content,
// modification times of its file and of its .meta file. It then checks that // the created_at in its .meta file, and the access and modification times of
// the variant is still served from the cache and that a new variant is made // its file and of its .meta file. It then checks that the variant is still
// from the cached source without fetching it again. // served from the cache and that a new variant is made from the cached source
// without fetching it again.
// //
// Left at the present: last_accessed_at in source_content and variant_content, // Left at the present: the files' status change and birth times, which a
// which is when eviction last saw the entry used, not when it was cached; the // program cannot set, and the times of the directories holding the files,
// files' status change and birth times, which a program cannot set; and the // which other entries share. The source's stored response headers are empty,
// times of the directories holding the files, which other entries share. The // as the mock fetcher sends none. expires_at, etag and last_modified in
// source's stored response headers are empty, as the mock fetcher sends none. // source_metadata and in the metadata file are never written, nor are the
// expires_at, etag and last_modified in source_metadata and in the metadata // request_cache and output_content tables.
// file are never written, nor are the request_cache and output_content tables.
func TestService_Get_ServesSourceAndVariantCachedTwoDaysAgo(t *testing.T) { func TestService_Get_ServesSourceAndVariantCachedTwoDaysAgo(t *testing.T) {
t.Parallel() t.Parallel()
@@ -522,6 +522,7 @@ func backdateSource(
updateOneRow(t, cache, updateOneRow(t, cache,
`UPDATE source_content SET fetched_at = ? WHERE content_hash = ?`, `UPDATE source_content SET fetched_at = ? WHERE content_hash = ?`,
dbTime, meta.ContentHash) dbTime, meta.ContentHash)
setSourceLastAccessed(t, cache, ContentHash(meta.ContentHash), when)
for _, path := range []string{ for _, path := range []string{
cache.srcContent.hashToPath(ContentHash(meta.ContentHash)), cache.srcContent.hashToPath(ContentHash(meta.ContentHash)),
@@ -571,6 +572,7 @@ func backdateVariant(
updateOneRow(t, cache, updateOneRow(t, cache,
`UPDATE variant_content SET created_at = ? WHERE cache_key = ?`, `UPDATE variant_content SET created_at = ? WHERE cache_key = ?`,
when.UTC().Format(sqliteTimestampFormat), string(key)) when.UTC().Format(sqliteTimestampFormat), string(key))
setVariantLastAccessed(t, cache, key, when)
for _, file := range []string{path, path + variantMetaSuffix} { for _, file := range []string{path, path + variantMetaSuffix} {
err = os.Chtimes(file, when, when) err = os.Chtimes(file, when, when)