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
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. Returnstrueif it existed. Manual deletion ignores pins, whoever holds them.override -
get(
String sha256) → Future< Uint8List?> -
Returns the bytes for
sha256, ornullif absent.override -
head(
String sha256) → Future< BlobDescriptor?> -
Returns the descriptor for
sha256without loading the bytes, ornullif 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. Returnstrueifbywas added,falseif it already held a pin or the blob does not exist.override -
put(
Uint8List bytes, {String? sha256, String? type, String? pinBy}) → Future< BlobDescriptor> -
Stores
bytesand 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. Returnstrueifbywas removed,falseif 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.