I implemented the standard LRUCache on Android, in which objects are stored. Each key is a unique ObjectId associated with a stored object. My problem is that the only way to get an object from the cache is ObjectId (without an iterator). What would be the best way to implement the getAll () method? Another option would be to store all ObjectIds in a list somewhere, so I can iterate over lists and get all objects - but what would be the best way to save all ObjectIds?
Thanks!
( ) LruCache, Android, snapshot, ( ObjectIds) ( ). - :
LruCache
snapshot
Map<ObjectIds, Object> snapshot = lruCache.snapshot(); for (ObjectIds id : snapshot.keySet()) { Object myObject = lruCache.get(id); }
Android LruCache, , . ( , , !)
lruCache.snapshot().values()
LRU. , ( , ). , , , , , Hashmap. .
In general, a list of all possible object keys in memory is used. If you need it, check if it is in the cache. If not, get it and add it to the cache.