8000 GitHub - findepi/evictable-cache
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Sep 28, 2024. It is now read-only.

findepi/evictable-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

evictable-cache

Evictable caches are caches that support eviction (invalidation) correctly.

Usage

If you are already using Guava's com.google.common.cache.CacheBuilder, just replace it with EvictableCacheBuilder. EvictableCacheBuilder is designed to be a drop-in replacement, providing strong visibility guarantees while hiding all the gory details behind Guava Cache and LoadingCache interfaces you're already familiar with.

Cache<String, Value> cache = EvictableCacheBuilder.newBuilder()
    .maximumSize(10_000)
    .expireAfterWrite(1, TimeUnit.HOURS)
    .build();

— or —

LoadingCache<String, Value> loadingCache = EvictableCacheBuilder.newBuilder()
        .maximumSize(10_000)
        .expireAfterWrite(1, TimeUnit.HOURS)
        .build(CacheLoader.from((String key) -> ...));

Installation

Get it from Maven Central

<dependency>
    <groupId>io.github.findepi</groupId>
    <artifactId>evictable-cache</artifactId>
    <version>2</version>
</dependency>

Other Java cache implementations

  • Guava Cache (which this library is baseed on). Awesome if you do not need strong visibility guarantees after invalidate() (or when you do not need invalidate() at all), or when cache usage is not concurrent (multi-threaded).
  • Caffeine (recommended by Guava javadocs). It comes in two flavors: synchronous and async.
    • Synchronous is awesome if you don't mind that invalidation blocks waiting for ongoing loads to finish.
    • Async is awesome if you do not need strong visibility guarantees after invalidate(), or some infrequent race conditions are acceptable.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  
0