Created
April 12, 2012 17:33
-
-
Save devnulled/2369406 to your computer and use it in GitHub Desktop.
Build A Simple Expiring Cache Based On Time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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