Skip to content
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

LRU cache #74

Closed
passsy opened this issue Oct 7, 2019 · 3 comments
Closed

LRU cache #74

passsy opened this issue Oct 7, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@passsy
Copy link

passsy commented Oct 7, 2019

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.

@passsy passsy added the enhancement New feature or request label Oct 7, 2019
@simc
Copy link
Member

simc commented Oct 8, 2019

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...

@simc
Copy link
Member

simc commented Oct 8, 2019

If other users want this feature, please upvote the issue 👍

@simc simc added this to the Stretch Goals milestone Oct 11, 2019
@simc simc removed this from the Stretch Goals milestone Feb 7, 2020
@themisir themisir closed this as completed Aug 9, 2020
@kvenn
Copy link

kvenn commented Aug 23, 2023

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants