multivalent

Class Cache

public class Cache extends Object

Cache ("a secure place of storage") holds not just set of recently seen pages, but important information such as Preferences and perhaps sole copy of automatically saved annotations.

Types of caches:

Later: check modification time of cached vs. original. If would go into general cache and didn't take long to fetch, maybe not cache at all.

Version: $Revision: 1.10 $ $Date: 2003/06/02 05:00:11 $

See Also: DocInfo

Field Summary
static intARCHIVE
static intCACHEONLY
static intCOMPUTE
static intDONTCACHE
static intGENERAL
static PatternHTTP_OLD_STATUS
static intUSER
Constructor Summary
Cache(String userdir, String tmpdir, CHashMap<String> genremap)
Method Summary
voidaddArchivePattern(String pattern)
voidchangeStatus(URI uri, String related, int fromtype, int totype)
voiddelete(URI uri, String related, int type)
voidflushAll()
voidflushCache(int type)
StringgetGenre(String contenttype, String filename, InputStream is)
InputStreamgetInputStream(URI uri)
Return InputStream that stores in cache, perhaps decompressing, retrieving from network if not in cache.
InputStreamgetInputStream(DocInfo di, String related, int type)
First normalizes URI.
FilegetOutputFile(URI uri, String related, int type, Map<String,String> headers)
Return OutputStream that stores in cache, perhaps compressing.
OutputStreamgetOutputStream(URI uri, String related, int type, Map<String,String> headers)
booleanisCached()
booleanisSeen(URI uri)
This ties whether seen page to whether it's in the cache, which can be wrong after cache is flushed.
booleanisSeen(String suri)
FilemapTo(URI uri, String related, int type)
Maps http://www.cs.berkeley.edu/~phelps/tcltk/index.html to basedir/edu/berkeley/cs/www/~phelps/tcltk/index.html/index.html
voidput(URI uri, String related, int type, byte[] data)
Can't overload return types to have a get retrun String too so caller should use String constructor with return value.
voidput(URI uri, String related, int type, String data, Map<String,String> headers)
voidsetSeen(String suri)
voidsetSeen(String suri, boolean seen)

Field Detail

ARCHIVE

public static final int ARCHIVE

CACHEONLY

public static final int CACHEONLY

COMPUTE

public static final int COMPUTE

DONTCACHE

public static final int DONTCACHE

GENERAL

public static final int GENERAL

HTTP_OLD_STATUS

public static final Pattern HTTP_OLD_STATUS

USER

public static final int USER

Constructor Detail

Cache

public Cache(String userdir, String tmpdir, CHashMap<String> genremap)

Method Detail

addArchivePattern

public void addArchivePattern(String pattern)

changeStatus

public void changeStatus(URI uri, String related, int fromtype, int totype)

delete

public void delete(URI uri, String related, int type)

flushAll

public void flushAll()

flushCache

public void flushCache(int type)

getGenre

public String getGenre(String contenttype, String filename, InputStream is)

getInputStream

public InputStream getInputStream(URI uri)
Return InputStream that stores in cache, perhaps decompressing, retrieving from network if not in cache. The InputStream is buffered. Compressed files of type gzip (indicated by suffix .gz, .Z, or .z) are automatically uncompressed in stream and the suffix is stripped from the returned, normalized URL. Client does Reader, Pushback as needed.

Parameters: type Type of cache

Throws: IOException (404, ...) FileNotFoundException

getInputStream

public InputStream getInputStream(DocInfo di, String related, int type)
First normalizes URI. Client probably wants to wrap returned InputStream in a BufferedInputStream. May mutate uri if redirects or lexical signature; original/requested URI available in uriin.

getOutputFile

public File getOutputFile(URI uri, String related, int type, Map<String,String> headers)
Return OutputStream that stores in cache, perhaps compressing. (Data automatically added to cache when getInputStream.)

Parameters: type Type of cache

getOutputStream

public OutputStream getOutputStream(URI uri, String related, int type, Map<String,String> headers)

isCached

public boolean isCached()

isSeen

public boolean isSeen(URI uri)
This ties whether seen page to whether it's in the cache, which can be wrong after cache is flushed.

isSeen

public boolean isSeen(String suri)

mapTo

public File mapTo(URI uri, String related, int type)
Maps http://www.cs.berkeley.edu/~phelps/tcltk/index.html to basedir/edu/berkeley/cs/www/~phelps/tcltk/index.html/index.html

Parameters: uri URI of base document (if null, use URI of cache) related Name of related file, such as "headers.txt" (if null, file is base document)

put

public void put(URI uri, String related, int type, byte[] data)
Can't overload return types to have a get retrun String too so caller should use String constructor with return value.

put

public void put(URI uri, String related, int type, String data, Map<String,String> headers)

setSeen

public void setSeen(String suri)

setSeen

public void setSeen(String suri, boolean seen)