public class

DefaultDiskStorage

extends Object
implements DiskStorage
java.lang.Object
   ↳ com.facebook.cache.disk.DefaultDiskStorage

Class Overview

The default disk storage implementation. Subsumes both 'simple' and 'sharded' implementations via a new SubdirectorySupplier.

Summary

Nested Classes
@interface DefaultDiskStorage.FileType Categories for the different internal files a ShardedDiskStorage maintains. 
Public Constructors
DefaultDiskStorage(File rootDirectory, int version, CacheErrorLogger cacheErrorLogger)
Instantiates a ShardedDiskStorage that will use the directory to save a map between keys and files.
Public Methods
void clearAll()
Clear all contents of the storage
boolean contains(String resourceId, Object debugInfo)
Does a resource with this name exist?
DiskStorage.DiskDumpInfo getDumpInfo()
List<DiskStorage.Entry> getEntries()
Get all entries currently in the storage
BinaryResource getResource(String resourceId, Object debugInfo)
Get the resource with the specified name
String getStorageName()
Get the storage's name, which should be unique
DiskStorage.Inserter insert(String resourceId, Object debugInfo)
Creates a temporary resource for writing content.
boolean isEnabled()
is this storage enabled?
boolean isExternal()
is this storage external?
void purgeUnexpectedResources()
long remove(DiskStorage.Entry entry)
Remove the resource represented by the entry
long remove(String resourceId)
Remove the resource with specified id
boolean touch(String resourceId, Object debugInfo)
Does a resource with this name exist? If so, update the last-accessed time for the resource
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.facebook.cache.disk.DiskStorage

Public Constructors

public DefaultDiskStorage (File rootDirectory, int version, CacheErrorLogger cacheErrorLogger)

Instantiates a ShardedDiskStorage that will use the directory to save a map between keys and files. The version is very important if clients change the format saved in those files. ShardedDiskStorage will assure that files saved with different version will be never used and eventually removed.

Parameters
rootDirectory root directory to create all content under
version version of the format used in the files. If passed a different version files saved with the previous value will not be read and will be purged eventually.
cacheErrorLogger logger for various events

Public Methods

public void clearAll ()

Clear all contents of the storage

public boolean contains (String resourceId, Object debugInfo)

Does a resource with this name exist?

Parameters
resourceId id of the resource
debugInfo helper object for debugging
Returns
  • true, if the resource is present in the storage, false otherwise

public DiskStorage.DiskDumpInfo getDumpInfo ()

Throws
IOException

public List<DiskStorage.Entry> getEntries ()

Get all entries currently in the storage

Returns
  • a collection of entries in storage
Throws
IOException

public BinaryResource getResource (String resourceId, Object debugInfo)

Get the resource with the specified name

Parameters
resourceId id of the resource
debugInfo helper object for debugging
Returns
  • the resource with the specified name. NULL if not found

public String getStorageName ()

Get the storage's name, which should be unique

Returns
  • name of the this storage

public DiskStorage.Inserter insert (String resourceId, Object debugInfo)

Creates a temporary resource for writing content. Split from commit() in order to allow concurrent writing of cache entries. This entry will not be available to cache clients until commit() is called passing in the resource returned from this method.

Parameters
resourceId id of the resource
debugInfo helper object for debugging
Returns
  • the Inserter object with methods to write data, commit or cancel the insertion
Throws
IOException

public boolean isEnabled ()

is this storage enabled?

Returns
  • true, if enabled

public boolean isExternal ()

is this storage external?

Returns
  • true, if external

public void purgeUnexpectedResources ()

public long remove (DiskStorage.Entry entry)

Remove the resource represented by the entry

Parameters
entry entry of the resource to delete
Returns
  • size of deleted file if successfully deleted, -1 otherwise

public long remove (String resourceId)

Remove the resource with specified id

Returns
  • size of deleted file if successfully deleted, -1 otherwise

public boolean touch (String resourceId, Object debugInfo)

Does a resource with this name exist? If so, update the last-accessed time for the resource

Parameters
resourceId id of the resource
debugInfo helper object for debugging
Returns
  • true, if the resource is present in the storage, false otherwise