Build 1.0_r1(from source)

android.webkit
Class CacheManager

java.lang.Object
  extended by android.webkit.CacheManager

public final class CacheManager
extends Object

The class CacheManager provides the persistent cache of content that is received over the network. The component handles parsing of HTTP headers and utilizes the relevant cache headers to determine if the content should be stored and if so, how long it is valid for. Network requests are provided to this component and if they can not be resolved by the cache, the HTTP headers are attached, as appropriate, to the request for revalidation of content. The class also manages the cache size.


Nested Class Summary
static class CacheManager.CacheResult
           
 
Field Summary
(package private) static String HEADER_KEY_IFMODIFIEDSINCE
           
(package private) static String HEADER_KEY_IFNONEMATCH
           
 
Constructor Summary
CacheManager()
           
 
Method Summary
static boolean cacheDisabled()
          get the state of the current cache, enabled or disabled
(package private) static boolean cacheEmpty()
          Return true if the cache is empty.
static CacheManager.CacheResult createCacheFile(String url, int statusCode, Headers headers, String mimeType, boolean forceCache)
          Given a url and its full headers, returns CacheResult if a local cache can be stored.
(package private) static boolean disableTransaction()
           
(package private) static boolean enableTransaction()
           
static boolean endCacheTransaction()
           
static CacheManager.CacheResult getCacheFile(String url, Map<String,String> headers)
          Given a url, returns the CacheResult if exists.
static File getCacheFileBaseDir()
          get the base directory of the cache.
(package private) static void init(Context context)
          initialize the CacheManager.
(package private) static boolean removeAllCacheFiles()
          remove all cache files
static void saveCacheFile(String url, CacheManager.CacheResult cacheRet)
          Save the info of a cache file for a given url to the CacheMap so that it can be reused later
(package private) static void setCacheDisabled(boolean disabled)
          set the flag to control whether cache is enabled or disabled
static boolean startCacheTransaction()
           
(package private) static void trimCacheIfNeeded()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HEADER_KEY_IFMODIFIEDSINCE

static final String HEADER_KEY_IFMODIFIEDSINCE
See Also:
Constant Field Values

HEADER_KEY_IFNONEMATCH

static final String HEADER_KEY_IFNONEMATCH
See Also:
Constant Field Values
Constructor Detail

CacheManager

public CacheManager()
Method Detail

init

static void init(Context context)
initialize the CacheManager. WebView should handle this for each process.

Parameters:
context - The application context.

getCacheFileBaseDir

public static File getCacheFileBaseDir()
get the base directory of the cache. With localPath of the CacheResult, it identifies the cache file.

Returns:
File The base directory of the cache.

setCacheDisabled

static void setCacheDisabled(boolean disabled)
set the flag to control whether cache is enabled or disabled

Parameters:
disabled - true to disable the cache

cacheDisabled

public static boolean cacheDisabled()
get the state of the current cache, enabled or disabled

Returns:
return if it is disabled

enableTransaction

static boolean enableTransaction()

disableTransaction

static boolean disableTransaction()

startCacheTransaction

public static boolean startCacheTransaction()

endCacheTransaction

public static boolean endCacheTransaction()

getCacheFile

public static CacheManager.CacheResult getCacheFile(String url,
                                                    Map<String,String> headers)
Given a url, returns the CacheResult if exists. Otherwise returns null. If headers are provided and a cache needs validation, HEADER_KEY_IFNONEMATCH or HEADER_KEY_IFMODIFIEDSINCE will be set in the cached headers.

Returns:
the CacheResult for a given url

createCacheFile

public static CacheManager.CacheResult createCacheFile(String url,
                                                       int statusCode,
                                                       Headers headers,
                                                       String mimeType,
                                                       boolean forceCache)
Given a url and its full headers, returns CacheResult if a local cache can be stored. Otherwise returns null. The mimetype is passed in so that the function can use the mimetype that will be passed to WebCore which could be different from the mimetype defined in the headers. forceCache is for out-of-package callers to force creation of a CacheResult, and is used to supply surrogate responses for URL interception.

Returns:
CacheResult for a given url

saveCacheFile

public static void saveCacheFile(String url,
                                 CacheManager.CacheResult cacheRet)
Save the info of a cache file for a given url to the CacheMap so that it can be reused later


removeAllCacheFiles

static boolean removeAllCacheFiles()
remove all cache files

Returns:
true if it succeeds

cacheEmpty

static boolean cacheEmpty()
Return true if the cache is empty.


trimCacheIfNeeded

static void trimCacheIfNeeded()

Build 1.0_r1(from source)

Please submit a feedback, bug or feature