Open tepozoa opened 23 hours ago
I'd need someone with some expertise on why the service worker would make removing the cached images impossible.
While I'm not particularly skilled with service workers, we have a dependency that should handle setting most of that stuff up automatically. From the webpack config:
const clientConfig = {
// Some stuff not relevant here...
plugins: [
...base.plugins,
new ServiceWorkerPlugin({
enableInDevelopment: mode !== "development", // this may seem counterintuitive, but it is correct
workbox: {
cacheId: "lemmy",
include: [/(assets|styles|js)\/.+\..+$/g],
inlineWorkboxRuntime: true,
runtimeCaching: [
{
urlPattern: ({
sameOrigin,
url: { pathname, host },
request: { method },
}) =>
(sameOrigin || host.includes("localhost")) &&
(!(
pathname.includes("pictrs") || pathname.includes("static")
) ||
method === "POST"),
handler: "NetworkFirst",
options: {
cacheName: "instance-cache",
},
},
{
urlPattern: ({ url: { pathname, host }, sameOrigin }) =>
(sameOrigin || host.includes("localhost")) &&
pathname.includes("static"),
handler: mode === "development" ? "NetworkFirst" : "CacheFirst",
options: {
cacheName: "static-cache",
expiration: {
maxAgeSeconds: 60 * 60 * 24,
},
},
},
{
urlPattern: ({ url: { pathname }, request: { method } }) =>
pathname.includes("pictrs") && method === "GET",
handler: "StaleWhileRevalidate",
options: {
cacheName: "image-cache",
expiration: {
maxAgeSeconds: 60 * 60 * 24,
},
},
},
],
},
}),
],
};
It's been awhile since I've touched this stuff, so I don't remember much of the context behind the caching decisions. Please feel free to criticize the config.
Minor Firefox debugging info: within the caches.sqlite
we have a cache_id
field which shows a mapping to the webpack-config code above; in my case ID 4 is the image-cache
matching /pictrs
URLs. There's then a table request_url
which maps a given URL to a numerical ID, then a table response_headers
which uses that ID to keep track of a date field (and all other headers, like cache-control etc.). The ID assigned to a URL is just an increasing integer, so in theory the lower the number the older the cache entry.
As I'd flushed my full storage as part of initial debugging, I'm now letting it fill back up again for a few days to try and capture a new caches.sqlite
which I might be able to expose stale entries beyond the expected 86400 setting for it to expire. I ran service-worker.js through a code beautifier and it sure looks like it's trying to expire entries. :-/
Requirements
Summary
I noticed under Firefox: Settings -> Privacy my local cookie/cache data was taking some 3G of space which felt off. I opened Manage Data, sorted by size and lo and behold lemm.ee (my home instance) was using all that space. I cleared the cache, verified empty in
about:cache
as empty yet the consumed lemm.ee space it was still listed. I had to resort to using the History function "forget this site" to actually clear out all used space.I'll try and present my findings, but I'm sort of guessing my way through this as an observer and end user, not a dev or instance admin. @sunaurus runs the instance and helps with Lemmy code, I hope they do not mind me tagging them into this issue.
Steps to Reproduce
about:cache
, restart FirefoxTechnical Details
In your local Firefox profile there exists the
storage/...
tree where each subdir is a named site (such as lemm.ee or lemmy.world, etc.) and several subdirs under that, with "default" being the one used in my observation. A quick look at the files sitting there reveals a lot of objects like this one:->
"snappy" is a compression format used by Firefox; a quick install of snappy-tools let me have a look at a copy of one of them, confirming it was a JPEG I had looked at moments ago (note I had to use the
-i
flag to ignore some checksum errors from rudimentary debugging):That said, it pulled right up in an image viewer as the JPEG. I then shut down Firefox, copied that same sqlite3 file to a test file (it's locked with WAL/SHM files while Firefox is running) and verified the chain of custody on that file after a quick look at the schema and following my nose:
It is here I must stop and see what your team thinks, as I do see what's happening logistically but am unsure what the expectation of either Firefox or Lemmy UI is to be; as an end user this "feels like" permanent local storage is being used/triggered by
service-worker.js
instead of it actually going to cache (thecache2/
subfolder, e.g.about:cache
view).I believe it a reasonable expectation as an end user that these images I'm looking at by the dozens if not hundreds are temporary, transient and should be in the cached data (as per
about:cache
etc.) and not being stored in site local storage which appears to be "forever" (requires manual Forget of the site to clear).Thank you!
Lemmy Instance Version
0.19.5
Lemmy Instance URL
https://lemm.ee/