public class

DiskBasedCache

extends Object
implements Cache
java.lang.Object
   ↳ com.android.volley.toolbox.DiskBasedCache

Class Overview

Cache implementation that caches files directly onto the hard disk in the specified directory. The default disk usage size is 5MB, but is configurable.

Summary

Public Constructors
DiskBasedCache(File rootDirectory, int maxCacheSizeInBytes)
Constructs an instance of the DiskBasedCache at the specified directory.
DiskBasedCache(File rootDirectory)
Constructs an instance of the DiskBasedCache at the specified directory using the default maximum cache size of 5MB.
Public Methods
synchronized void clear()
Clears the cache.
synchronized Cache.Entry get(String key)
Returns the cache entry with the specified key if it exists, null otherwise.
File getFileForKey(String key)
Returns a file object for the given cache key.
synchronized void initialize()
Initializes the DiskBasedCache by scanning for all files currently in the specified root directory.
synchronized void invalidate(String key, boolean fullExpire)
Invalidates an entry in the cache.
synchronized void put(String key, Cache.Entry entry)
Puts the entry with the specified key into the cache.
synchronized void remove(String key)
Removes the specified key from the cache if it exists.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.android.volley.Cache

Public Constructors

public DiskBasedCache (File rootDirectory, int maxCacheSizeInBytes)

Constructs an instance of the DiskBasedCache at the specified directory.

Parameters
rootDirectory The root directory of the cache.
maxCacheSizeInBytes The maximum size of the cache in bytes.

public DiskBasedCache (File rootDirectory)

Constructs an instance of the DiskBasedCache at the specified directory using the default maximum cache size of 5MB.

Parameters
rootDirectory The root directory of the cache.

Public Methods

public synchronized void clear ()

Clears the cache. Deletes all cached files from disk.

public synchronized Cache.Entry get (String key)

Returns the cache entry with the specified key if it exists, null otherwise.

Parameters
key Cache key
Returns

public File getFileForKey (String key)

Returns a file object for the given cache key.

public synchronized void initialize ()

Initializes the DiskBasedCache by scanning for all files currently in the specified root directory. Creates the root directory if necessary.

public synchronized void invalidate (String key, boolean fullExpire)

Invalidates an entry in the cache.

Parameters
key Cache key
fullExpire True to fully expire the entry, false to soft expire

public synchronized void put (String key, Cache.Entry entry)

Puts the entry with the specified key into the cache.

Parameters
key Cache key
entry Data to store and metadata for cache coherency, TTL, etc.

public synchronized void remove (String key)

Removes the specified key from the cache if it exists.

Parameters
key Cache key