| AndBase开发框架 1.6

- 首页
- 相关页面
- 命名空间
- 类
- 文件

- 类列表
- 类索引
- 类继承关系
- 类成员

全部 类 命名空间 文件 函数 变量 枚举值 页
类 | Public 成员函数 | 静态包函数 | Private 成员函数 | 静态 Private 成员函数 | Private 属性 | 静态 Private 属性 | 所有成员列表
com.ab.network.toolbox.DiskBasedCache类 参考
类 com.ab.network.toolbox.DiskBasedCache 继承关系图:

## 类
class | CacheHeader
class | CountingInputStream

## Public 成员函数
| DiskBasedCache (File rootDirectory, int maxCacheSizeInBytes)
| DiskBasedCache (File rootDirectory)
synchronized void | clear ()
synchronized Entry | get (String key)
synchronized void | initialize ()
synchronized void | invalidate (String key, boolean fullExpire)
synchronized void | put (String key, Entry entry)
synchronized void | remove (String key)
File | getFileForKey (String key)

## 静态包函数
static void | writeInt (OutputStream os, int n) throws IOException
static int | readInt (InputStream is) throws IOException
static void | writeLong (OutputStream os, long n) throws IOException
static long | readLong (InputStream is) throws IOException
static void | writeString (OutputStream os, String s) throws IOException
static String | readString (InputStream is) throws IOException
static void | writeStringStringMap (Map< String, String > map, OutputStream os) throws IOException
static Map< String, String > | readStringStringMap (InputStream is) throws IOException

## Private 成员函数
String | getFilenameForKey (String key)
void | pruneIfNeeded (int neededSpace)
void | putEntry (String key, CacheHeader entry)
void | removeEntry (String key)

## 静态 Private 成员函数
static byte[] | streamToBytes (InputStream in, int length) throws IOException
static int | read (InputStream is) throws IOException

## Private 属性
final Map< String, CacheHeader > | mEntries
long | mTotalSize = 0
final File | mRootDirectory
final int | mMaxCacheSizeInBytes

## 静态 Private 属性
static final int | DEFAULT_DISK_USAGE_BYTES = 5 * 1024 * 1024
static final float | HYSTERESIS_FACTOR = 0.9f
static final int | CACHE_MAGIC = 0x20120504

## 详细描述

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

## 构造及析构函数说明

com.ab.network.toolbox.DiskBasedCache.DiskBasedCache | ( | File | rootDirectory,
|  | int | maxCacheSizeInBytes
| ) |  |
| inline

Constructs an instance of the DiskBasedCache at the specified directory.

参数

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

com.ab.network.toolbox.DiskBasedCache.DiskBasedCache | ( | File | rootDirectory | ) |
| inline

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

参数

  rootDirectory | The root directory of the cache.

## 成员函数说明

synchronized void com.ab.network.toolbox.DiskBasedCache.clear | ( |  | ) |
| inline

Clears the cache. Deletes all cached files from disk.

实现了 com.ab.network.toolbox.Cache.

synchronized Entry com.ab.network.toolbox.DiskBasedCache.get | ( | String | key | ) |
| inline

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

实现了 com.ab.network.toolbox.Cache.

File com.ab.network.toolbox.DiskBasedCache.getFileForKey | ( | String | key | ) |
| inline

Returns a file object for the given cache key.

String com.ab.network.toolbox.DiskBasedCache.getFilenameForKey | ( | String | key | ) |
| inline private

Creates a pseudo-unique filename for the specified cache key.

参数

  key | The key to generate a file name for.

返回
  A pseudo-unique filename.

synchronized void com.ab.network.toolbox.DiskBasedCache.initialize | ( |  | ) |
| inline

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

实现了 com.ab.network.toolbox.Cache.

synchronized void com.ab.network.toolbox.DiskBasedCache.invalidate | ( | String | key,
|  | boolean | fullExpire
| ) |  |
| inline

Invalidates an entry in the cache.

参数

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

实现了 com.ab.network.toolbox.Cache.

void com.ab.network.toolbox.DiskBasedCache.pruneIfNeeded | ( | int | neededSpace | ) |
| inline private

Prunes the cache to fit the amount of bytes specified.

参数

  neededSpace | The amount of bytes we are trying to fit into the cache.

synchronized void com.ab.network.toolbox.DiskBasedCache.put | ( | String | key,
|  | Entry | entry
| ) |  |
| inline

Puts the entry with the specified key into the cache.

实现了 com.ab.network.toolbox.Cache.

void com.ab.network.toolbox.DiskBasedCache.putEntry | ( | String | key,
|  | CacheHeader | entry
| ) |  |
| inline private

Puts the entry with the specified key into the cache.

参数

  key | The key to identify the entry by.
  entry | The entry to cache.

static int com.ab.network.toolbox.DiskBasedCache.read | ( | InputStream | is | ) | throws IOException
| inline static private

Simple wrapper around InputStream#read() that throws EOFException instead of returning -1.

static int com.ab.network.toolbox.DiskBasedCache.readInt | ( | InputStream | is | ) | throws IOException
| inline static package

static long com.ab.network.toolbox.DiskBasedCache.readLong | ( | InputStream | is | ) | throws IOException
| inline static package

static String com.ab.network.toolbox.DiskBasedCache.readString | ( | InputStream | is | ) | throws IOException
| inline static package

static Map<String, String> com.ab.network.toolbox.DiskBasedCache.readStringStringMap | ( | InputStream | is | ) | throws IOException
| inline static package

synchronized void com.ab.network.toolbox.DiskBasedCache.remove | ( | String | key | ) |
| inline

Removes the specified key from the cache if it exists.

实现了 com.ab.network.toolbox.Cache.

void com.ab.network.toolbox.DiskBasedCache.removeEntry | ( | String | key | ) |
| inline private

Removes the entry identified by 'key' from the cache.

static byte [] com.ab.network.toolbox.DiskBasedCache.streamToBytes | ( | InputStream | in,
|  | int | length
| ) |  | throws IOException
| inline static private

Reads the contents of an InputStream into a byte[].

static void com.ab.network.toolbox.DiskBasedCache.writeInt | ( | OutputStream | os,
|  | int | n
| ) |  | throws IOException
| inline static package

static void com.ab.network.toolbox.DiskBasedCache.writeLong | ( | OutputStream | os,
|  | long | n
| ) |  | throws IOException
| inline static package

static void com.ab.network.toolbox.DiskBasedCache.writeString | ( | OutputStream | os,
|  | String | s
| ) |  | throws IOException
| inline static package

static void com.ab.network.toolbox.DiskBasedCache.writeStringStringMap | ( | Map< String, String > | map,
|  | OutputStream | os
| ) |  | throws IOException
| inline static package

## 类成员变量说明

final int com.ab.network.toolbox.DiskBasedCache.CACHE_MAGIC = 0x20120504
| static private

Magic number for current version of cache file format.

final int com.ab.network.toolbox.DiskBasedCache.DEFAULT_DISK_USAGE_BYTES = 5 * 1024 * 1024
| static private

Default maximum disk usage in bytes.

final float com.ab.network.toolbox.DiskBasedCache.HYSTERESIS_FACTOR = 0.9f
| static private

High water mark percentage for the cache

final Map<String, CacheHeader> com.ab.network.toolbox.DiskBasedCache.mEntries
| private

初始值:
=
new LinkedHashMap<String, CacheHeader>(16, .75f, true)

Map of the Key, CacheHeader pairs

final int com.ab.network.toolbox.DiskBasedCache.mMaxCacheSizeInBytes
| private

The maximum size of the cache in bytes.

final File com.ab.network.toolbox.DiskBasedCache.mRootDirectory
| private

The root directory to use for the cache.

long com.ab.network.toolbox.DiskBasedCache.mTotalSize = 0
| private

Total amount of space currently used by the cache in bytes.

该类的文档由以下文件生成:

- src/com/ab/network/toolbox/DiskBasedCache.java