Ashwinstein / kitty-cache

Automatically exported from code.google.com/p/kitty-cache
0 stars 0 forks source link

KittyCache.put removes key instead of toRemove #2

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When adding a new item beyond the size limite it seems that tries to remove the 
oldest object in, but the code is not expressin that. Instead it tries to 
remove the same key that was trying to put 

 if (toRemove != null) {
                remove(key);
 }

all the code...

public void put(Object key, Object val, Integer seconds_to_store) {
        if(key == null) throw new RuntimeException("Key cannot be null!");
        seconds_to_store = seconds_to_store != null ? seconds_to_store : 9999999;
        cache.put(key, new Object[]{System.currentTimeMillis() + seconds_to_store, val});
        queue.add(key);
        size.incrementAndGet();

        while (size.get() > maxSize && maxSize > 0) {
            Object toRemove = queue.poll();
            if(toRemove == null) break;
//            System.out.println("toRemove=" + toRemove + " size=" + size.get() 
+ " maxSize=" + maxSize);
            if (toRemove != null) {
                remove(key);
            }
        }
    }

am I miss understanding?

Federico

Original issue reported on code.google.com by federico...@gmail.com on 17 Feb 2011 at 4:39

GoogleCodeExporter commented 8 years ago
should be remove(toRemove) instead remove(key)

Original comment by jrbalder...@gmail.com on 2 Nov 2011 at 9:42

GoogleCodeExporter commented 8 years ago

Original comment by innovati...@gmail.com on 19 Dec 2011 at 6:49