Questions tagged [google-guava-cache]
97 questions
2
votes
1 answer
How to figure out whether a key exists in guava cache so that I don't overwrite it?
I have a guava cache and I want to figure out whether a particular key already exists or not so that I don't overwrite them? Is this possible to do with Guava cache?
private final Cache cache = CacheBuilder.newBuilder()
…

john
- 11,311
- 40
- 131
- 251
2
votes
1 answer
Does Google Guava Cache do deduplication when refreshing value of the same key
I implemented a non-blocking cache using Google Guava, there's only one key in the cache, and value for the key is only refreshed asynchronously (by overriding reload()).
My question is that does Guava cache handle de-duplication if the first…

Hanchi Wang
- 43
- 6
2
votes
1 answer
Spring metrics don't show Guava hit/miss
In the metrics endpoint I get all the caches size, but not hit/miss (as expected from https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-metrics.html#production-ready-datasource-cache)
Example:
"cache.mytest.size":19
I…

Leo
- 1,066
- 1
- 6
- 19
2
votes
1 answer
How to empty Guava cache every 30 seconds while sending it to another method?
I am populating my guava cache from multiple threads by calling add method. Now from the background thread which runs every 30 seconds, I want to send whatever is there in the cache to sendToDB method atomically?
Below is my code:
public class…

john
- 11,311
- 40
- 131
- 251
2
votes
1 answer
Using Google Guava to get List
I am new to Guava and I want to return comma separated list of users essentially a String. I am using one third party API to fetch the list. I want to cache that list and return that entire list if user queries.
I looked at few examples online and…
user3519456
2
votes
1 answer
Probabilistic Early Expiration with Guava Cache
I have a Guava cache created with expireAfterWrite(20, TimeUnit.MINUTES). The cache is also initialized with dozens of entries when created. When values expire, client is supposed to call an external service and refresh the cache.
Problem is - all…

bdhar
- 21,619
- 17
- 70
- 86
2
votes
2 answers
Does Google Guava Cache load on same thread?
Does Google Guava Cache load the cache on the same thread by default?
Code:
cache = CacheBuilder
.newBuilder()
.refreshAfterWrite(2, TimeUnit.SECONDS)
.build(new CacheLoader() {
@Override
public String…

tourniquet_grab
- 792
- 9
- 14
2
votes
2 answers
Google Guava Cache on weak reference value not giving notification on eviction
I have used google guava in our application based on weakValues like below.
CacheBuilder
.newBuilder()
.weakValues()
.concurrencyLevel(Runtime.getRuntime().availableProcessors())
…

user2203937
- 181
- 1
- 8
2
votes
1 answer
How to get duplicate elements in array list using guava predicates
I have a array with set of elements. I need to find the duplicate elements in that array by comparing particular field using guava predicated in java.
For example:
I have an arraylist with set of employees details. I need to find details of…

Krieger
- 31
- 1
- 6
2
votes
1 answer
Thread parked on waiting on condition on AbstractFuture
so we are using Guava v18.
We are going a lot of thread with this content:
"catalina-exec-ajp2" daemon prio=10 tid=0x00007fb45c001800 nid=0x18aa waiting on condition [0x00007fb435151000]
java.lang.Thread.State: WAITING (parking)
at…

dierre
- 7,140
- 12
- 75
- 120
1
vote
0 answers
Return TreeMap as value from Guava's cache
I have a map as defined below:
Map>, TreeMap targetMap = new HashMap<>();
I want to add eviction and maximum size properties to it, as we do for cache through Guava. Is there a way to handle this logic through…

Manav Gupta
- 21
- 4
1
vote
2 answers
How to cache some active data only based on the result from external storage in Guava?
Here is the background: I have a 1 billion users in my external storage and most of them will be accessed at least once in a day, but only some active data will be accessed much more.
So for Guava, I may write:
cache.get(key, new Callable() {
…

JaskeyLam
- 15,405
- 21
- 114
- 149
1
vote
1 answer
Guava - Caching a table and using get methods on that one cache
I've previously implemented caching in my application, to be used with three separate get methods. These get methods are getAllProfiles(), getProfilesByID(), and getProfileByFields(). Because of this, my code looks like this:
private…

SVill
- 331
- 5
- 22
- 55
1
vote
1 answer
How does Guava caching stand in terms of performance?
I want to use Guava caching mechanism to cache request-response pair of webservice calls to improve performance of website. But, before going ahead with solution want to know how does Guava caching stand in terms of performance?
Thanks,
Ashish.

AshishK
- 171
- 1
- 2
- 8
1
vote
0 answers
Evicting In-Memory Cache across multiple instances?
How do we evict in-memory caches at different instances?
We have a scale-out architecture, multiple instances service requests simultaneously. Each one of them has in-memory cache attached to it.
We need eviction accross all instance, at once.
Why…

Mohsin Mansoor
- 155
- 1
- 1
- 8