org.mmbase.module
Class scancache

Package class diagram package scancache
java.lang.Object
  extended by org.mmbase.util.functions.FunctionProvider
      extended by org.mmbase.util.functions.DescribedFunctionProvider
          extended by org.mmbase.module.Module
              extended by org.mmbase.module.scancache
All Implemented Interfaces:
Descriptor, scancacheInterface

public class scancache
extends Module
implements scancacheInterface

File cache system. This system only caches texts (it stores and retrieves strings). Texts are asociated with a key, which is used both as a filename on disk and a key into a memory cache. While in theory it is possible to cache ANY text, this module is mainly used to store pages based on their url.
Caching is done in pools. Each pool has its own memory cache and files, and has different ways to handle file caching. The pools currently supported are "PAGE" and "HENK".

Version:
$Id: scancache.java 35335 2009-05-21 08:14:41Z michiel $
Author:
Daniel Ockeloen, Pierre van Rooden (javadocs)
Application:
SCAN
Rename:
SCANCache

Field Summary
static int MAX_CACHE_POOL_SIZE
          Maximum size of a pool's memory cache.
(package private)  MMBase mmbase
          reference to MMBase module, used to retrieve netfiles and pagemakers builders that support caching.
(package private)  Hashtable<String,LRUHashtable<String,String>> pools
          Contains the memory caches for the cache pools.
(package private)  boolean status
          Determines whether the cache module is active.
(package private)  LRUHashtable<String,Integer> timepool
          Contains the last date (as an Integer) a file was stored in a pool.
 
Fields inherited from class org.mmbase.module.Module
configurationPath, getMaintainerFunction, getVersionFunction, properties, STATE_START_TIME
 
Fields inherited from class org.mmbase.util.functions.DescribedFunctionProvider
description, guiName, name
 
Fields inherited from class org.mmbase.util.functions.FunctionProvider
functions, getFunctions
 
Constructor Summary
scancache()
          Scancache module constructor.
 
Method Summary
 String get(String poolName, String key, scanpage sp)
          Retrieve a file from the indicated pool's cache.
 String get(String poolName, String key, String line, scanpage sp)
          Retrieve a file from the indicated pool's cache.
 long getExpireDate(String poolName, String key, String expireStr)
          getExpireDate.
 long getLastModDate(String poolName, String key)
          getLastModDate.
 String getModuleInfo()
          Retrieve a description of the module's function.
 boolean getStatus()
          Returns the status of this module.
(package private)  String getWriteHeaders(String value, String mimeType)
          Returns the headers for a .asis file to be stored for a "PAGE" cache.
 void init()
          Initializes the module.
 fileInfo loadFile(String pool, String filename)
          loads a file from the disk.
 String newput(String poolName, HttpServletResponse res, String key, String value, String mimeType)
          Store a file in the indicated pool's cache (both on file system and in the memory cache).
 String newput2(String poolName, String key, String value, int cachetype, String mimeType)
          Store a file in the indicated pool's cache (both in file and in the memory cache).
 void onload()
          Event that should be triggered when the module is loaded.
 String put(String poolName, String key, String value)
          Store a file in the indicated pool's cache (both on file and in the memory cache).
 void remove(String poolName, String key)
          Removes an entry from the cache pool (both the file on disk and in the memory cache).
 void shutdown()
          Event that sh*ould be triggered when the module is shut down.
 void signalNetFileSrv(String filename)
          Signal the NetFileServ builder that the .asis file for a page has changed.
 void unload()
          Event that should be triggered when the module is unloaded.
 
Methods inherited from class org.mmbase.module.Module
, addInitParameters, checkModules, getInitParameter, getInitParameter, getInitParameter, getInitParameters, getInitParameters, getMaintainer, getModule, getModule, getModule, getModule, getModuleLoader, getModuleReader, getModuleReader, getModules, getState, getStates, getVersion, hasModule, hasStarted, loadInitParameters, loadInitParameters, maintainance, setInitParameter, setMaintainer, setState, setVersion, shutdownModules, startModule, startModules
 
Methods inherited from class org.mmbase.util.functions.DescribedFunctionProvider
getDefaultLocale, getDescription, getDescription, getGUIName, getGUIName, getLocalizedDescription, getLocalizedGUIName, getName, setDescription, setDescription, setGUIName, setGUIName, setLocalizedDescription, setLocalizedGUIName, setName
 
Methods inherited from class org.mmbase.util.functions.FunctionProvider
addFunction, createParameters, getFunction, getFunctions, getFunctionValue, newFunctionInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_CACHE_POOL_SIZE

public static final int MAX_CACHE_POOL_SIZE
Maximum size of a pool's memory cache.

See Also:
Constant Field Values

pools

Hashtable<String,LRUHashtable<String,String>> pools
Contains the memory caches for the cache pools. Pools are identified by name. Various pools have different ways of cache-handling. The pools currently supported are 'HENK' and 'PAGE'. The key to retrieve a pool is the poolname. The value returned ia a LRUHashtable, configured to hold a maximum of MAX_CACHE_POOL_SIZE entries.


timepool

LRUHashtable<String,Integer> timepool
Contains the last date (as an Integer) a file was stored in a pool. The key to retrieve the time is poolname+filekey (where a filekey is generally the file URI). There is a limit to the number of values stored in this pool. This means if you have more then 4 pooltypes you have to bump that value or suffer performance degredation


mmbase

MMBase mmbase
reference to MMBase module, used to retrieve netfiles and pagemakers builders that support caching.


status

boolean status
Determines whether the cache module is active. Set by the status field in the scancache.xml configuration file.

Constructor Detail

scancache

public scancache()
Scancache module constructor.

Method Detail

onload

public void onload()
Event that should be triggered when the module is loaded. Unused.

Overrides:
onload in class Module

shutdown

public void shutdown()
Event that sh*ould be triggered when the module is shut down. Unused.

Overrides:
shutdown in class Module

unload

public void unload()
Event that should be triggered when the module is unloaded. Unused.


init

public void init()
Initializes the module. Reads parameters from the scancache.xml configuration file.

Specified by:
init in interface scancacheInterface
Overrides:
init in class Module

get

public String get(String poolName,
                  String key,
                  scanpage sp)
Retrieve a file from the indicated pool's cache. When using the "HENK" pool, this method performs a check on expiration using the default expiration time (6 hours). For cache "PAGE", this method does not check expiratio, and retrieves the data from the file from disk, NOT from the memory cache.

Specified by:
get in interface scancacheInterface
Parameters:
poolName - name of the cache pool, either "HENK" or "PAGE"
key - URL of the page to retrieve
Returns:
the page's content as a string, or null if no entry was found (i.e. cache was empty or poolname was invalid).

get

public String get(String poolName,
                  String key,
                  String line,
                  scanpage sp)
Retrieve a file from the indicated pool's cache. It is first retrieved from meory. if that fails, the file is retrieved from disk. This method performs a check on expiration using either the default expiration time (6 hours), or the value in the line parameter. This method returns an old version of the page if the page in the cache has expired. It will signal the scanparser to calculate a new one in the background. This avoids contention on a busy server as the page is only calculated once when expired not calculate every request that comes in during the window of calculation.

Specified by:
get in interface scancacheInterface
Parameters:
poolName - name of the cache pool, expected (but not verified) are "HENK" or "PAGE"
key - URL of the page to retrieve
line - the expiration value, either the expiration value in seconds or the word 'NOEXPIRE'. Due to legacy this value needs to be closed with a '>'. If the parameter is empty a default value is used.
Returns:
the page's content as a string, or null if no entry was found

getExpireDate

public long getExpireDate(String poolName,
                          String key,
                          String expireStr)
getExpireDate.

Specified by:
getExpireDate in interface scancacheInterface
Parameters:
poolName -
key -
expireStr -
Returns:
long

getLastModDate

public long getLastModDate(String poolName,
                           String key)
getLastModDate.

Specified by:
getLastModDate in interface scancacheInterface
Parameters:
poolName -
key -
Returns:
long

newput

public String newput(String poolName,
                     HttpServletResponse res,
                     String key,
                     String value,
                     String mimeType)
Store a file in the indicated pool's cache (both on file system and in the memory cache). Returns the old value if available. When using the "HENK" pool, this method performs a check on expiration using the default expiration time (6 hours). For cache "PAGE", this method does not check expiration, and retrieves the data from the file from disk, NOT from the memory cache.

Specified by:
newput in interface scancacheInterface
Parameters:
poolName - name of the cache pool, either "HENK" or "PAGE"
res - response object for retrieving headers (used by mmbase.org?) only needed for cachepool "PAGE"
key - URL of the page to store
value - the page content to store
mimeType - the page's mime type, only needed for cachepool "PAGE"
Returns:
the page's old content as a string, or null if no entry was found (i.e. cache was empty or poolName was invalid).

newput2

public String newput2(String poolName,
                      String key,
                      String value,
                      int cachetype,
                      String mimeType)
Store a file in the indicated pool's cache (both in file and in the memory cache). Returns the old value if available. Is used in scanpage to recalculate the cached page.

Specified by:
newput2 in interface scancacheInterface
Parameters:
poolName - name of the cache pool, either "HENK" or "PAGE"
key - URL of the page to store
value - the page content to store
cachetype - only needed for cachepool "PAGE". If 0, no file transfer is performed. Otherwise the NetFileSrv builder is invoked to start the VWM that handles the transfer.
mimeType - the page's mime type, only needed for cachepool "PAGE"
Returns:
the page's old content as a string, or null if no entry was found (i.e. cache was empty or poolName was invalid).

put

public String put(String poolName,
                  String key,
                  String value)
Store a file in the indicated pool's cache (both on file and in the memory cache). Returns the old value if available.

Specified by:
put in interface scancacheInterface
Parameters:
poolName - name of the cache pool
key - URL of the page to store
value - the page content to store
Returns:
the page's old content as a string, or null if no entry was found

getModuleInfo

public String getModuleInfo()
Retrieve a description of the module's function.

Overrides:
getModuleInfo in class Module

loadFile

public fileInfo loadFile(String pool,
                         String filename)
loads a file from the disk. The file retrieved is stored in the cache root directory, followed by the poolname (HENK or PAGE), followed by the 'original' file name.

Parameters:
pool - The name of the pool
filename - the name of the file
Returns:
the content of the file in a fileInfo object.

signalNetFileSrv

public void signalNetFileSrv(String filename)
Signal the NetFileServ builder that the .asis file for a page has changed. The builder then searches the responsible VWM that handles the mirrorring of the pages, and activates it.

Parameters:
filename - the .asis filename that changed

getWriteHeaders

String getWriteHeaders(String value,
                       String mimeType)
Returns the headers for a .asis file to be stored for a "PAGE" cache.

Parameters:
value - page content, used to set the Content-length header.
mimeType - the mimetype of the page. default (if unspecified) is text/html; iso-8859-1
Returns:
the page headers as a String

remove

public void remove(String poolName,
                   String key)
Removes an entry from the cache pool (both the file on disk and in the memory cache). If the pool is "PAGE", the file will only be removed from the local cache, not from any mirror servers.

Specified by:
remove in interface scancacheInterface
Parameters:
poolName - name of cache pool, expected (but not verified) "HENK" or "PAGE"
key - URL of the page to remove

getStatus

public boolean getStatus()
Returns the status of this module.

Returns:
true if the module is active, false otherwise


MMBase Scan 2.0-SNAPSHOT - 2013-03-30T06:50