greenrobot-common 2.3 with improved ObjectCache

Version 2.3 of greenrobot-common was just released and brings a new cache implementation: as the class ObjectCache suggests, caches a number of objects in memory. The API is used in a key-value like fashion, very much like a Map. It comes with a couple of cache-specific features though:

  • A maximum number of cache entries is defined. Once that limit is reached, old entries are evicted from the cache. The order of put matters for eviction: the entries first putted, are the first ones removed.
  • Value reference types: you can choose if values are strongly, softly or weakly referenced. For example, for big cache values or in constrained memory environments, softly referenced objects can be reclaimed by the VM.
  • Expiration times: You can configure the cache to expire items after a defined time delay.

Android developers may notice the similarities to LruCache. ObjectCache is not restricted to Android but can be used in any Java project. Also, LruCache is a bit more limited as it always uses strong references, and has no time based expiration.

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Posted in Open Source, Release and tagged , , , .