How to remove specific json feed cache in Volley? clear() works, but remove(url) does not work
<p>I have an adapter for Volley to handle HTTP requests using OKhttp3 as the transport and <code>DiskBasedCache</code> as the caching implementation. </p>

<p>I'm trying to remove a specific JSON feed request from the cache by using <code>.remove(url)</code> but it isn't working. Here's an example code:</p>

<p>Make a request in an activity:</p>

<pre><code>String url = "http://somewebsite.com/feed.json"

VolleyStringRequest stringRequest = new VolleyStringRequest(Method.GET,null, url,responseListener(),errorListener());

RequestQueue queue = CustomVolleyRequestQueue.getInstance(context).getRequestQueue();

queue.add(stringRequest);
</code></pre>

<p>Remove the cache after something has been done:</p>

<pre><code>Cache cache = CustomVolleyRequestQueue.getInstance(context).getRequestQueue().getCache();

Cache.Entry cacheEntry = cache.get(url);

if (cacheEntry != null) {
     Log.d("cache", "has_cache");
} else {
     Log.d("cache", "no cache");
}

cache.remove(url);
</code></pre>

<p>However, in the logCat, the key <code>url</code> returns "no cache", and the <code>cache.remove(url)</code> produces </p>

<pre><code> DiskBasedCache.remove: Could not delete cache entry for key=http://somewebsite.com/feed.json, 
 filename=-159673043453434434
</code></pre>

<p>Does anyone know how to use <code>cache.remove(url)</code>? Does Volley use url as cache entries' keys? I don't want to use <code>cache.clear()</code> but just remove a specific request cache.</p>

<p>CustomVolleyRequestQueue :</p>

<pre><code>public class CustomVolleyRequestQueue {

    private static CustomVolleyRequestQueue mInstance;
    private static Context mCtx;
    private RequestQueue mRequestQueue;

    private CustomVolleyRequestQueue(Context context) {
        mCtx = context;
        mRequestQueue = getRequestQueue();
    }

    public static synchronized CustomVolleyRequestQueue getInstance(Context context) {
        if (mInstance == null) {
            mInstance = new CustomVolleyRequestQueue(context);
        }
        return mInstance;
    }

    public RequestQueue getRequestQueue() {
        if (mRequestQueue == null) {
            Cache cache = new DiskBasedCache(mCtx.getCacheDir(), 10 * 1024 * 1024);
            Network network = new BasicNetwork(new OkHttpStack());
            mRequestQueue = new RequestQueue(cache, network);
            // Don't forget to start the volley request queue
            mRequestQueue.start();
        }
        return mRequestQueue;
    }
}
</code></pre>

<p>UPDATE: I have made a custom class that extends <code>DiskBasedCache</code> to check what key it uses for the cache. </p>

<pre><code>public class CustomDiskBasedCache extends DiskBasedCache {

    public CustomDiskBasedCache(File rootDirectory, int maxCacheSizeInBytes) {
        super(rootDirectory, maxCacheSizeInBytes);
    }

    @Override
    public synchronized void put(String key, Entry entry) {
        super.put( key,  entry);
        Log.d("cache_key",key);
    }
}
</code></pre>

<p>It looks like every cache key is prefixed with <code>0:</code>, for example:</p>

<p><code>0:http://somewebsite.com/feed.json</code></p>

<p>I don't know why it is added. </p>