org.mmbase.module
Class scancache

java.lang.Object
  |
  +--org.mmbase.module.Module
        |
        +--org.mmbase.module.scancache
All Implemented Interfaces:
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:
10 Apr 2001
Author:
Daniel Ockeloen, Pierre van Rooden (javadocs)

Field Summary
static int MAX_CACHE_POOL_SIZE
          Maximum size of a pool's memory cache.
 
Constructor Summary
scancache()
          Scancache module constructor.
 
Method Summary
 java.lang.String get(java.lang.String poolName, java.lang.String key, scanpage sp)
          Retrieve a file from the indicated pool's cache.
 java.lang.String get(java.lang.String poolName, java.lang.String key, java.lang.String line, scanpage sp)
          Retrieve a file from the indicated pool's cache.
 java.lang.String getModuleInfo()
          Retrieve a description of the module's function.
 java.lang.String getNew(java.lang.String poolName, java.lang.String key, java.lang.String line, scanpage sp)
          Retrieve a file from the indicated pool's cache.
 java.lang.String getPage(java.lang.String poolName, java.lang.String key, java.lang.String line)
          Retrieve a file from disk.
 boolean getStatus()
          Returns the status of this module.
 void init()
          Initializes the module.
 fileInfo loadFile(java.lang.String pool, java.lang.String filename)
          loads a file to disk.
 void maintainance()
          maintainance call, will be called by the admin to perform managment tasks.
 java.lang.String newput(java.lang.String poolName, javax.servlet.http.HttpServletResponse res, java.lang.String key, java.lang.String value, java.lang.String mimeType)
          Store a file in the indicated pool's cache (both on file and in teh memory cache).
 java.lang.String newput2(java.lang.String poolName, java.lang.String key, java.lang.String value, int cachetype, java.lang.String mimeType)
          Deprecated. Temporary hack for solving asis problems (?). Use newput(java.lang.String, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String, java.lang.String) instead.
 void onload()
          Event that should be triggered when the module is loaded.
 java.lang.String put(java.lang.String poolName, java.lang.String key, java.lang.String value)
          Store a file in the indicated pool's cache (both on file and in the memory cache).
 void remove(java.lang.String poolName, java.lang.String key)
          Removes an entry from the cache pool (both the file on disk and in the memory cache).
 boolean saveFile(java.lang.String pool, java.lang.String filename, java.lang.String value)
          Saves a file to disk.
 void shutdown()
          Event that sh*ould be triggered when the module is shut down.
 void signalNetFileSrv(java.lang.String filename)
          Signal the NetFileServ builder that the .asis file for a page has changed.
 java.util.Hashtable state()
          state, returns the state hashtable that is/can be used to debug.
 void unload()
          Event that should be triggered when the module is unloaded.
 
Methods inherited from class org.mmbase.module.Module
getClassName, getInitParameter, getInitParameters, getMaintainer, getMimeType, getMimeTypeFile, getModule, getModule, getModules, getName, getProperties, getProperty, getVersion, hasStarted, loadModulesFromDisk, setClassName, setInitParameter, setMaintainer, setName, setVersion, startModule, startModules
 
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.
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.

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 java.lang.String get(java.lang.String poolName,
                            java.lang.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).

getNew

public java.lang.String getNew(java.lang.String poolName,
                               java.lang.String key,
                               java.lang.String line,
                               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 expiration, and retrieves the data from the file from disk, NOT from the memory cache.
Specified by:
getNew in interface scancacheInterface
Parameters:
poolname - name of the cache pool, either "HENK" or "PAGE"
key - URL of the page to retrieve
line - contains parameters for counters, expiration time, etc, in tag-format. For this method, these options are currently only used at the mmbase.org site.
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 java.lang.String get(java.lang.String poolName,
                            java.lang.String key,
                            java.lang.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

getPage

public java.lang.String getPage(java.lang.String poolName,
                                java.lang.String key,
                                java.lang.String line)
Retrieve a file from disk. This method loads a file from disk and returns the contents as a string. It does not use the memory cache of a poolname, nor does it check for expiration of the cache. Also, it does not perform updates on the memory cache.
Parameters:
poolname - name of the cache pool (expected, but not verified is "PAGE")
key - URL of the page to retrieve
line - cache line options, unspecified
Returns:
the page's content as a string, or null if no entry was found

newput

public java.lang.String newput(java.lang.String poolName,
                               javax.servlet.http.HttpServletResponse res,
                               java.lang.String key,
                               java.lang.String value,
                               java.lang.String mimeType)
Store a file in the indicated pool's cache (both on file and in teh 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 - reponse 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 java.lang.String newput2(java.lang.String poolName,
                                java.lang.String key,
                                java.lang.String value,
                                int cachetype,
                                java.lang.String mimeType)
Deprecated. Temporary hack for solving asis problems (?). Use newput(java.lang.String, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String, java.lang.String) instead.

Store a file in the indicated pool's cache (both in file and in the memory cache). Returns the old value if available.
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
int - 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 java.lang.String put(java.lang.String poolName,
                            java.lang.String key,
                            java.lang.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

state

public java.util.Hashtable state()
Description copied from class: Module
state, returns the state hashtable that is/can be used to debug. Should be overridden when live state should be done.
Overrides:
state in class Module

maintainance

public void maintainance()
maintainance call, will be called by the admin to perform managment tasks. This can be used instead of its own thread.
Overrides:
maintainance in class Module

getModuleInfo

public java.lang.String getModuleInfo()
Retrieve a description of the module's function.
Overrides:
getModuleInfo in class Module

saveFile

public boolean saveFile(java.lang.String pool,
                        java.lang.String filename,
                        java.lang.String value)
Saves a file to disk. The file is stored under the cache root directory, with a unique name, composed of the pool name and the 'original' file name.
Parameters:
pool - The name of the pool
filename - the name of the file
value - the value to store in the file

loadFile

public fileInfo loadFile(java.lang.String pool,
                         java.lang.String filename)
loads a file to disk. The file retrieved should be stored under the cache root directory, with a unique name, composed of the pool name and 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(java.lang.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

remove

public void remove(java.lang.String poolName,
                   java.lang.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:
pool - 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 2002