Skip to content

[shared_preferences] Consider making async accessors, with optional caching layer #123078

@stuartmorgan-g

Description

@stuartmorgan-g

Based on discussion while adding prefix support to shared_preferences, and previous discussion in #101691, we should consider deprecating the current API and building a new API with the cache outside the public API instead of inside its implementation.

This version could consist of two different public API layers:

  1. Setters and getters that are all async, and are direct passthroughs to the underlying storage. Prefixing would be fully optional.
    • We could either make it not part of this layer at all, leaving it entirely to clients of this API layer, or we could allow creating arbitrary instances with optional prefixes. (Since there is no singleton+cache at this layer, we would not have to worry about cache consistency issues.)
  2. A separate cache object, with an API more like the current API, built on the underlying async API. We could:
    • have no "shared instance" logic at all (leaving it entirely to clients to manage their cache instances), or
    • build in something more flexible than the current singleton. E.g., maybe allow something like a global ID-keyed map, where you would ask for an instance with certain properties (such as key prefix) and you'd get a key back that you could use to access that same shared instance in the future. In this version we'd need to make it very clear that the caches would be distinct, and strongly discourage overlapping caches (e.g., a no-prefix cache and a prefixed cache) to avoid synchronization issues.

We'd want to fully evaluate all the flexibility we'd need to meet open requests (different storage files/domains, etc.) before designing the new API so we could incorporate all of it up front in at least layer 1.

(@tarrinneal just capturing based on recent thoughts and discussions while it's fresh in our minds; not something we need to do in the short term.)

Metadata

Metadata

Assignees

Labels

Bot is counting down the days until it unassigns the issueP3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityp: shared_preferencesPlugin to read and write Shared Preferencespackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions