0

I'm using java 8 and guava 14.0

I set up a LoadingCache and a CacheLoader with a load(). The code works every time I get from the cache the load () is called

There are times where I want to check if data is in the cache without calling the load(). Is this possible?

I tried using the getIfPresent() but I still see the load() being called.

I was looking at AsMap but concerned with the size of this since it gets all the data from the cache

Thanks in advance for any info/suggestions

Barry

Barry F
  • 71
  • 1
  • 4

1 Answers1

0

I'm not sure what your concern is with asMap; that returns a view, not an entire copy; the cost of using asMap is O(1). That said, it surprises me that getIfPresent still causes a load; that makes me suspicious that some other part of your program is calling load, because getIfPresent should not cause that to happen.

Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413