FileBlossomCache class

A BlossomCache that stores each blob as its own file and keeps only the metadata in a small sembast database. Memory use does not grow with the size of the blobs, so it fits caches of tens of gigabytes. Native and server only.

open takes a directory dedicated to the cache. It holds meta.db and a blobs/ folder with one file per blob, named by its sha256:

// Flutter, with package:path_provider
final support = await getApplicationSupportDirectory();
final cache = await FileBlossomCache.open(
  path: p.join(support.path, 'blossom_cache'),
);

Keys become file names, so they must be lowercase hex sha256 strings.

Implemented types

Properties

hashCode → int
The hash code for this object.
no setterinherited
path → String
The directory holding the cache.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

clearAllLocalData() → Future<void>
Removes every blob and its metadata, pinned ones included.
override
close() → Future<void>
Closes the metadata database. Subsequent operations will throw.
delete(String sha256) → Future<bool>
Removes the blob with sha256. Returns true if it existed. Manual deletion ignores pins, whoever holds them.
override
get(String sha256) → Future<Uint8List?>
Returns the bytes for sha256, or null if absent.
override
Returns the descriptor for sha256 without loading the bytes, or null if absent. Equivalent to a Blossom HEAD request.
override
list() → Future<List<BlobDescriptor>>
Lists every blob descriptor currently held by the cache.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pin(String sha256, {String by = BlossomCache.defaultHolder}) → Future<bool>
Pins the blob on behalf of by. Automatic eviction skips a blob while at least one holder pins it. Returns true if by was added, false if it already held a pin or the blob does not exist.
override
put(Uint8List bytes, {String? sha256, String? type, String? pinBy}) → Future<BlobDescriptor>
Stores bytes and returns the descriptor.
override
toString() → String
A string representation of this object.
inherited
unpin(String sha256, {String by = BlossomCache.defaultHolder}) → Future<bool>
Releases the pin held by by. The blob stays pinned if other holders remain. Returns true if by was removed, false if it held no pin or the blob does not exist.
override
unpinAll(String by) → Future<int>
Releases every pin held by by, e.g. when an account logs out. Returns the number of blobs that lost a pin.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

open({required String path}) → Future<FileBlossomCache>
Opens (or creates) the cache in the directory at path.