DaveAKing / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

A cache with all the data, not a subset #1419

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I often have these APIs that return a lot of elements. I want to cache the 
results. But at each request towards the cache, I need only one element.

It would be nice to have an option in CacheBuilder that forces loading all the 
elements and that knows that all the data have been fetched, so it doesn't need 
extra calls to the backend in order to get an error.

Typically, here's what I'd want:

The API I call has the following data: "foo" -> "a", "bar" -> "b"

LoadingCache cache = ...; // empty cache
String foo = cache.get("foo"); // calls loadAll(), puts "foo" and "bar" in 
cache, returns "a"
String bar = cache.get("bar"); // doesn't call loadAll(), returns "b"
String baz = cache.get("baz"); // doesn't call loadAll(), returns null or 
throws exception.
Thread.sleep(...); // expires all elements
baz = cache.get("baz"); // calls loadAll(), puts "foo" and "bar" in cache, 
returns null or throws exception

Currently we can have a Cache that does that if our CacheLoader.loadAll() 
actually loads all, but we need to use cache.getAll(ImmutableList.of("foo")). 
But a call to the backend will be performed when we call 
cache.getAll(ImmutableList.of("baz")). This feels awkward.

Original issue reported on code.google.com by ogregoire on 21 May 2013 at 2:10

GoogleCodeExporter commented 9 years ago

Original comment by cgdec...@gmail.com on 21 May 2013 at 5:25

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:12

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:17

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08