nostra13 / Android-Universal-Image-Loader

Powerful and flexible library for loading, caching and displaying images on Android.
Apache License 2.0
16.78k stars 6.1k forks source link

Skipping caching of distinct image #891

Open AlexTrotsenko opened 9 years ago

AlexTrotsenko commented 9 years ago

If app shows image once per start (e.g. background loading image on start-up), it could be nice to have ability to skip caching this image in memory cache.

Specially it could be handy for time-based cache. LRU cache could also contribute from this as well.

AlexTrotsenko commented 9 years ago

Looks like I have found the way to avoid keeping unnecessary image in cache. It will still caches it with normal call, but after that I can remove it from memory with call like:

MemoryCacheUtils.removeFromCache(backgroundImgUri, ImageLoader.getInstance().getMemoryCache());

iman2420 commented 7 years ago

How to remove From Cache for all images?

ouyangzn commented 7 years ago

@iman2420 Here is some method in class ImageLoader. I think it is what you wanted.

/**
     * Returns memory cache
     *
     * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before
     */
    public MemoryCache getMemoryCache() {
        checkConfiguration();
        return configuration.memoryCache;
    }

    /**
     * Clears memory cache
     *
     * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before
     */
    public void clearMemoryCache() {
        checkConfiguration();
        configuration.memoryCache.clear();
    }

    /**
     * Returns disk cache
     *
     * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before
     */
    public DiskCache getDiskCache() {
        checkConfiguration();
        return configuration.diskCache;
    }

    /**
     * Clears disk cache.
     *
     * @throws IllegalStateException if {@link #init(ImageLoaderConfiguration)} method wasn't called before
     */
    public void clearDiskCache() {
        checkConfiguration();
        configuration.diskCache.clear();
    }