Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading javadoc of CacheBuilder #2442

Open
vermahim opened this issue Apr 4, 2016 · 2 comments
Open

Misleading javadoc of CacheBuilder #2442

vermahim opened this issue Apr 4, 2016 · 2 comments
Assignees
Labels
P3 package=cache type=api-docs Change/add API documentation

Comments

@vermahim
Copy link

vermahim commented Apr 4, 2016

Hi,

Javadoc of CacheBuilder says it uses LRU as eviction policy, but my test says otherwise..

`private static void testCacheEvictionPolicy() {
int maxSz = 3;
LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder().maximumSize(maxSz).build(new CacheLoader<Integer, Integer>() {
@OverRide
public Integer load(Integer integer) throws Exception {
return integer;
}
});
callCache(cache, 3);
printCache(cache);
for (int i = 0; i < 1000; i++) {
callCache(cache, 1);
}
callCache(cache, 4);
printCache(cache);
}

private static void callCache(LoadingCache<Integer, Integer> cache, int n) {
    for (int i = 1; i <= n; i++) {
        try {
            cache.get(i);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    }

}

private static void printCache(LoadingCache<Integer, Integer> cache) {
    System.out.println("cache begin");
    for (Map.Entry<Integer, Integer> entry : cache.asMap().entrySet()) {
        System.out.println(entry.getKey() + " : " + entry.getValue());
    }
    System.out.println("cache end");
}`

output:

cache begin
3 : 3
2 : 2
1 : 1
cache end
cache begin
3 : 3
2 : 2
4 : 4
cache end

@kluever kluever added type=api-docs Change/add API documentation package=cache labels Apr 4, 2016
@lowasser
Copy link
Contributor

lowasser commented Apr 4, 2016

What the cache does is LRU, but on a per-segment basis: the cache is divided into concurrencyLevel segments, each of which does LRU internally with a size cap of maximumSize/concurrencyLevel.

@kluever
Copy link
Member

kluever commented Apr 4, 2016

It's probably worth adding this clarification to the javadocs.

GuyPaddock pushed a commit to GuyPaddock/guypaddock.github.io that referenced this issue Apr 7, 2018
@cpovirk cpovirk added the P3 label Jul 25, 2019
@kluever kluever assigned kluever and unassigned lowasser Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 package=cache type=api-docs Change/add API documentation
Projects
None yet
Development

No branches or pull requests

4 participants