Skip to content

Instantly share code, notes, and snippets.

@devnulled
Created April 12, 2012 17:33
Show Gist options
  • Select an option

  • Save devnulled/2369406 to your computer and use it in GitHub Desktop.

Select an option

Save devnulled/2369406 to your computer and use it in GitHub Desktop.
Build A Simple Expiring Cache Based On Time
// Requires Google Guava 10 or greater
Cache<Key, Graph> graphs = CacheBuilder.newBuilder()
.concurrencyLevel(4)
.weakKeys()
.maximumSize(10000)
.expireAfterWrite(10, TimeUnit.MINUTES)
.build(
new CacheLoader<Key, Graph>() {
public Graph load(Key key) throws AnyException {
return createExpensiveGraph(key);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment