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> { |
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) { |