krazycoder / google-collections

Automatically exported from code.google.com/p/google-collections
Apache License 2.0
0 stars 0 forks source link

MapMaker to create a bounded cache #236

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm using a computing map for things whose values are quite heavy and could
use cleanup.  I'd like to restrict to a particular number of entries, or
attempt to.  The behavior would be that after entries go over a certain
limit, the least recently used one gets knocked off.

something like this...

MapMaker().lru(20, new CleanUp<V>(){
   public void cleanup(V toCleanup){
      //close resources   
   }
}).makeComputingMap(new Function(K, V){
   public V apply(K key){
      return expensiveResource(key);
   } 
});

Original issue reported on code.google.com by adrian.f...@gmail.com on 13 Sep 2009 at 4:43

GoogleCodeExporter commented 9 years ago
We don't like LRU because it inevitably leads to locking in get(). We are, 
however,
experimenting with lock-free eviction algorithms such as clock-pro, so that you 
can
get the boundedness you desire without sacrificing concurrency.

Original comment by kevin...@gmail.com on 13 Sep 2009 at 7:33

GoogleCodeExporter commented 9 years ago
that works for me. 

looking closer at my request, I've noticed there are 2 enhancements: 
boundedness and
a hook for cleaning up evicted resources.  are you ok with both being here, or 
should
I open another issue for cleanup?

Original comment by adrian.f...@gmail.com on 13 Sep 2009 at 8:07

GoogleCodeExporter commented 9 years ago
Feel free to split them up. We are working on them separately.

Original comment by yrfselrahc@gmail.com on 13 Sep 2009 at 1:19

GoogleCodeExporter commented 9 years ago

Original comment by kevin...@gmail.com on 17 Sep 2009 at 4:50

GoogleCodeExporter commented 9 years ago

Original comment by kevin...@gmail.com on 17 Sep 2009 at 4:51

GoogleCodeExporter commented 9 years ago

Original comment by kevin...@gmail.com on 17 Sep 2009 at 5:45

GoogleCodeExporter commented 9 years ago

Original comment by kevin...@gmail.com on 17 Sep 2009 at 5:52

GoogleCodeExporter commented 9 years ago
Kevin, not sure why you merged. There are two distinct features: bounded size, 
and removal notifcations.

Original comment by yrfselrahc@gmail.com on 17 Sep 2009 at 7:05

GoogleCodeExporter commented 9 years ago
the accident was my changing the summary on this one at the same time as I 
dup'd it 
out. Someone should still file a separate issue about the removal notification.

Original comment by kevin...@gmail.com on 17 Sep 2009 at 7:45

GoogleCodeExporter commented 9 years ago
Given that we already have issue #167 to track the bounded size, let's use this 
issue to track removal 
notification, as it has a perfect use case.

Original comment by yrfselrahc@gmail.com on 17 Sep 2009 at 8:02

GoogleCodeExporter commented 9 years ago
I guess the description here does focus more on the boundedness, so I'll move 
this back into 167 (sorry Kevin) 
and create a new one for removal.

Original comment by yrfselrahc@gmail.com on 18 Sep 2009 at 12:26