/[projects]/android/TrainInfo/src/dk/thoerup/traininfo/util/AndroidTimeoutCache.java
ViewVC logotype

Diff of /android/TrainInfo/src/dk/thoerup/traininfo/util/AndroidTimeoutCache.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1031 by torben, Wed Sep 8 06:03:45 2010 UTC revision 1032 by torben, Wed Sep 8 09:29:42 2010 UTC
# Line 1  Line 1 
1  package dk.thoerup.traininfo.util;  package dk.thoerup.traininfo.util;
2    
3  import java.util.HashMap;  import java.util.HashMap;
4    import java.util.Iterator;
5    import java.util.Set;
6    
7    import android.util.Log;
8    
9    
10  public class AndroidTimeoutCache<K,V> {  public class AndroidTimeoutCache<K,V> {
# Line 26  public class AndroidTimeoutCache<K,V> { Line 30  public class AndroidTimeoutCache<K,V> {
30          public void purgeOldEntries() {          public void purgeOldEntries() {
31                                    
32                  long now = android.os.SystemClock.elapsedRealtime();                  long now = android.os.SystemClock.elapsedRealtime();
33                    //Log.e("Purge","Purge");
34                    
35                    Set<K> keyset = cache.keySet();
36                                    
37                  for (K key : cache.keySet()) {                  for ( Iterator<K> it = keyset.iterator(); it.hasNext() ;) {
38                            K key = it.next();
39                            
40                          CacheItem<V> item = cache.get(key);                          CacheItem<V> item = cache.get(key);
41                          if ( (item.lastupdate+timeout) < now) { //item too old                          if ( (item.lastupdate+timeout) < now) { //item too old
42                                  cache.remove(key);                                  it.remove();
43                          }                                  //Log.e("Purge", "removing");
44                  }                          }                      
45                    }      
46                    
47          }          }
48                    
49          public void put(K k, V v) {          public void put(K k, V v) {

Legend:
Removed from v.1031  
changed lines
  Added in v.1032

  ViewVC Help
Powered by ViewVC 1.1.20