Android Open Source - music-tag Cache Service






From Project

Back to project page music-tag.

License

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.

Java Source Code

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));
    }


}




Java Source Code List

binauld.pierre.musictag.ApplicationTest.java
binauld.pierre.musictag.activities.MainActivity.java
binauld.pierre.musictag.activities.SettingsActivity.java
binauld.pierre.musictag.activities.TagFormActivity.java
binauld.pierre.musictag.activities.TagSuggestionActivity.java
binauld.pierre.musictag.adapter.LibraryItemAdapter.java
binauld.pierre.musictag.adapter.SuggestionItemAdapter.java
binauld.pierre.musictag.adapter.SuggestionViewHolder.java
binauld.pierre.musictag.collection.LibraryItemComparator.java
binauld.pierre.musictag.collection.MultipleBufferedList.java
binauld.pierre.musictag.decoder.AudioFileBitmapDecoder.java
binauld.pierre.musictag.decoder.BitmapDecoder.java
binauld.pierre.musictag.decoder.ResourceBitmapDecoder.java
binauld.pierre.musictag.factory.FileFilterFactory.java
binauld.pierre.musictag.factory.LibraryItemFactory.java
binauld.pierre.musictag.fragments.SettingsFragment.java
binauld.pierre.musictag.helper.LibraryItemFactoryHelper.java
binauld.pierre.musictag.helper.LoaderHelper.java
binauld.pierre.musictag.io.ArtworkLoader.java
binauld.pierre.musictag.io.AsyncDrawable.java
binauld.pierre.musictag.io.DefaultArtworkLoader.java
binauld.pierre.musictag.io.LibraryItemLoaderManager.java
binauld.pierre.musictag.io.LibraryItemLoader.java
binauld.pierre.musictag.io.SuggestionLoader.java
binauld.pierre.musictag.item.AudioItem.java
binauld.pierre.musictag.item.ChildItem.java
binauld.pierre.musictag.item.FolderItem.java
binauld.pierre.musictag.item.LibraryItem.java
binauld.pierre.musictag.item.LoadingState.java
binauld.pierre.musictag.item.NodeItem.java
binauld.pierre.musictag.item.SuggestionItem.java
binauld.pierre.musictag.service.ArtworkService.java
binauld.pierre.musictag.service.CacheService.java
binauld.pierre.musictag.service.Locator.java
binauld.pierre.musictag.tag.Id3TagParcelable.java
binauld.pierre.musictag.tag.Id3Tag.java
binauld.pierre.musictag.tag.SupportedTag.java
binauld.pierre.musictag.widget.AnimatedProgressBar.java