-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Session Buckets #44
Comments
"session" seems hard to define, whereas "expiration" is easy to define/understand. This makes me think that a hard date is likely to satisfy as many use cases as "session". |
What I understand from our discussion in whatwg/storage#71 to be about was storage that:
Without the tab-as-namespace constraint, I think it would indeed be quite difficult to define a session, but thankfully that's not the case. I think there are a few big advantages to this:
In particular, I think it's beneficial to think of a use-case for websites that provide rich web app functionality that's exclusively client-side by default. For example https://app.diagrams.net/ is a diagramming site that can use a bunch of cloud storage providers, but can also just store things locally in the browser. "Session" storage could actually provide a stronger reliability guarantee for the user than normal storage eviction. This is in contrast to cloud-first apps where the storage model is explicitly that the canonical storage is in the cloud and client side storage is a cache or a scratchpad, etc. The biggest question in my mind would be how far the tab-session-buckets would be exposed:
|
Agree with @asutherland ... how this will interact with automatic unloading of background tabs? I presume that such unloaded tabs would not have their bucket cleared, since they are restorable. Handling restore (and I presume reload) does add some complication since the site will need to deal with their cache not being empty at load time, but that should be easy to deal with. One could clear it in those cases, but that might impose some unexpected performance hits when going back to an unloaded tab and on reload (both from having to reload/regenerate the data from the cloud, and the clearing overhead on reload) |
Good points! Here is my tldr: I think we should have a "short term" bucket that is evicted soonish (this is just a hint to the user agent) after it's not being used. If sites want to the lifetime to match SessionStorage, they can store the name/ID for this bucket in SessionStorage, and rest assured that once they stop accessing it, it will not last much longer. Longer format: I will agree there is likely value in creating an explicit "short term" expiration duration. Seems better not to force it to be linked to a single tab though, if we can implement it as usable in both ways (multi-tab sessions with the ability for single-tab). Two main points I want to cover:
I'll cover the latter first. I don't think we want to make new guarantees that data will not be deleted at any point because But if we have a definition of session, we can say that the data won't stick around taking up quota accessible after the session is over. And if we have some hint that a bucket is "sessiony" then a user agent can use that hint to make eviction more or less likely, such as by surfacing the information to the user or applying it to the automatic eviction algorithm. Now to define short term/session. I don't think tab lifespan defines it very well nor does it future-proof the definition very well.
It seems likely someone wants data that is not to be tab-namespaced, but still goes away after the multi-tab session is over. In the image editor example, I suspect many users open multiple tabs/windows in a single image editing session. If you do want a tab-namespaced session bucket, you can just be sure to only access it from a single tab and store the name in I think we have to work a bit heuristically here, and perhaps this is not to be spec'd but implementation defined. But my idea for what most closely approximates user expectations is:
Thoughts? |
I have a modest proposal for how we can turn the tab lifetime issue into an implementation issue. Refcounted Buckets! Thanks to history APIs state storage being based on structured serialization per spec, it's possible to create opaque identifiers or bucket references that can only be cloned or retrieved by iterating over all currently existing refcounted buckets:
If we're not providing strong tab guarantees and instead doing time-based heuristics like:
Then perhaps we just want a different mode of expiration. Right now expiration is defined as ~"must expire by" as opposed to ~"please keep around until, but I don't mind if you keep it around longer". |
Something like this would be particularly useful for minimizing memory usage for encoding/decoding from large archives (on mobile 1GB total memory for the whole device is not uncommon). I originally opened this on fs, but basically a storage bucket that are GC collected would be highly convenient for transient archives. e.g. Usage would look something like: type FileSource = ArrayBuffer | Blob | ReadableStream | FileSystemFileHandle;
class Archive {
static async create(): Promise<Archive> {
// STRAWMAN API: Allows the bucket to be automatically be collected when all references to the bucket (including file handles) are collected
const bucket = await navigator.storageBuckets.openTempBucket();
return new Archive(bucket);
}
readonly #bucket: StorageBucket;
constructor(bucket: StorageBucket) {
this.#bucket = bucket;
}
async addFile(name: string, source: FileSource): Promise<void> {
const rootDir = await this.#bucket.getDirectory();
const file = await rootDir.getFile(name, { create: true });
// Write the file from the source
}
async getFile(name: string): Promise<FileSystemFileHandle> {
const rootDir = await this.#bucket.getDirectory();
return await rootDir.getFile(name);
}
// This would extra efficient with https://github.com/whatwg/fs/issues/114
async encodeZip(): Promise<FileSystemFileHandle> {
// Note we don't use the archive's bucket, as if the returned zip file is collected
// the bucket can be reclaimed even sooner
const zipBucket = await navigator.storageBuckets.openTempBucket();
const zipRootDir = await zipBucket.getDirectory();
const zipFile = await zipRootDir.getFile("out.zip", { create: true });
// ... Iterate files in the archive storage bucket and encode them into the zipFile
// Return the zipFile, if it's collected then the corresponding file on disk can be
// destroyed also
return zipFile;
}
} |
There are some compelling use cases for having a bucket's lifetime be tied to a "session".
Should we consider having adding a policy that would allow for this on bucket creation?
As a part of this we should also (re)define what "session" means.
Related links:
The text was updated successfully, but these errors were encountered: