Back to project page music-tag.
The source code is released under:
Apache License
If you think the Android project music-tag listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package binauld.pierre.musictag.service; //w ww. j a v a2 s.c o m import android.util.LruCache; public class CacheService<Resource> { private LruCache<String, Resource> cache; public CacheService() { // Use 1/8th of the available memory for this memory cache. this.cache = new LruCache<>((int) (Runtime.getRuntime().maxMemory() / 1024 / 8)); } /** * Put a resource in the cache. * @param key The resource key. * @param resource The resource to put in the cache. */ public void put(String key, Resource resource) { if (cache.get(key) == null) { cache.put(key, resource); } } /** * Get a resource from the cache associated to the key. * @param key The resource key. * @return A resource. */ public Resource get(String key) { return cache.get(key); } /** * Get a resource from the cache associated to the key. * @param key The resource key. * @return A resource. */ public Resource get(int key) { return cache.get(String.valueOf(key)); } }