You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to use hive as an LRU cache to cache HTTP responses using lazy boxes.
LRU caches have two possible constraints to remove old entries:
Keep a maximum number of entries in the cache (50)
Limit entries to disk space usage (10mb)
It's ugly but already possible
No new API is required to build a LRU cache with hive. By adding a timestamp to every entry it is already possible to detect the oldest item. But querying for the oldest item requires loading the complete value. This is memory-consuming and therefore fails the purpose of a LazyBox.
Possible improvements
Expose Order
A Box already knows about the order entries were added (append-only data store). By exposing the order of the entries through the Box API as an ordered list of keys, it would be possible to delete the oldest items without loading any value from disk.
Expose used disk space
A box could expose its size (in bytes) allowing deletion of old entries after reaching a certain size. I prefer setting maxCacheSize instead of a fixed number of items when it comes to image caching.
First party "persistent cache" support
Instead of exposing new low-level APIs, hive could provide a first-class LruBox with properties like maxEntryCount or cacheSize.
I'd like to know if a LRU cache is in scope of this project.
The text was updated successfully, but these errors were encountered:
I really like the idea but I don't want to complicate the API. I think it would be a good idea to create a new package hive_lru. This should already be possible without changes to Hive itself.
The only thing that needs some changes is the maxCacheSize. I don't know if it is possible to provide the size of a frame without big changes to Hive.
It might take some time before I can implement this feature. First I want to implement queries and improve the unit tests. After that I'll start working on the LRU cache.
If you need this feature faster, I'll support you when you have questions...
I'd be interested in this feature. We're using graphql-flutter which is backed by Hive. It can grow infinitely and it would be ideal if there was support at the Hive level (without needing to implement our own wrapper).
I'd like to use hive as an LRU cache to cache HTTP responses using lazy boxes.
LRU caches have two possible constraints to remove old entries:
It's ugly but already possible
No new API is required to build a LRU cache with hive. By adding a timestamp to every entry it is already possible to detect the oldest item. But querying for the oldest item requires loading the complete
value
. This is memory-consuming and therefore fails the purpose of aLazyBox
.Possible improvements
Expose Order
A
Box
already knows about the order entries were added (append-only data store). By exposing the order of the entries through theBox
API as an ordered list of keys, it would be possible to delete the oldest items without loading anyvalue
from disk.Expose used disk space
A box could expose its size (in bytes) allowing deletion of old entries after reaching a certain size. I prefer setting
maxCacheSize
instead of a fixed number of items when it comes to image caching.First party "persistent cache" support
Instead of exposing new low-level APIs, hive could provide a first-class
LruBox
with properties likemaxEntryCount
orcacheSize
.I'd like to know if a LRU cache is in scope of this project.
The text was updated successfully, but these errors were encountered: