Common Lisp Package: COM.INFORMATIMAGO.COMMON-LISP.CESARUM.CACHE

This package implements a generic disk-based cache. Example: (defparameter *web-cache* (make-instance 'cache :directory-path "CACHE:WEB;" :value-file-type "HTML" :producer (function get-url))) (cache-get *web-cache* "http://www.informatimago.com/") --> "&lt;!DOCTYPE html PUBLIC …" ; :FETCHED (cache-get *web-cache* "http://www.informatimago.com/") --> "&lt;!DOCTYPE html PUBLIC …" ; :IN-CORE License: AGPL3 Copyright Pascal J. Bourguignon 2005 - 2012 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>

README:

FUNCTION

Public

ENTRY-EXPIRE-DATE (INSTANCE)

RETURN: The universal-time when the entry expires.

ENTRY-FETCH-DATE (INSTANCE)

RETURN: The universal-time when the entry was stored.

ENTRY-FILE-NAME (INSTANCE)

RETURN: The name of the file where the value is stored.

ENTRY-KEY (INSTANCE)

RETURN: The key of the entry.

ENTRY-VALUE (INSTANCE)

PRE: (entry-value-p entry) RETURN: The value of the entry.

ENTRY-VALUE-P (INSTANCE)

RETURN: Whether the value of the entry is loaded.

MAKE-CACHE (DIRECTORY PRODUCER &KEY VALUE-FILE-TYPE)

DO: Make a new cache instance. NOTE: Send synchronize

Undocumented

SETFENTRY-EXPIRE-DATE (NEW-VALUE INSTANCE)

SETFENTRY-FETCH-DATE (NEW-VALUE INSTANCE)

SETFENTRY-FILE-NAME (NEW-VALUE INSTANCE)

SETFENTRY-KEY (NEW-VALUE INSTANCE)

SETFENTRY-VALUE (NEW-VALUE INSTANCE)

SETFENTRY-VALUE-P (NEW-VALUE INSTANCE)

Private

CACHE-HEADER-P (HEADER)

RETURN: Whether HEADER is a cache index file header.

CACHE-RECORD-P (RECORD)

RETURN: Whether RECORD is a cache index file record.

COMPARE-CACHE-DATE (A B)

A,B: Time stamps (cache date) are (universal-time . increment). RETURN: -1 <=> a<b, 0 <=> a=b, +1 <=> a>b

Undocumented

CACHE-TEST

COPY-ENTRY (INSTANCE)

ENTRY-P (OBJECT)

INDEX-GET (INDEX KEY)

INDEX-MAP-ENTRIES (RESULT-TYPE FUN INDEX)

INDEX-PUT (INDEX ENTRY)

INDEX-REMOVE (INDEX KEY)

MAKE-ENTRY (&KEY ((KEY DUM53) NIL) ((VALUE DUM54) NIL) ((VALUE-P DUM55) NIL) ((FILE-NAME DUM56) ) ((FETCH-DATE DUM57) 0) ((EXPIRE-DATE DUM58) 0))

MAKE-INDEX

SAFE-RENAME-FILE (OLD-NAME NEW-NAME)

VALUE-FILE-PATH (DIRECTORY NAME TYPE)

GENERIC-FUNCTION

Public

CACHE-EXPIRATION (CACHE KEY)

RETURN: NIL or the universal-time of expiration of the CACHE.

CACHE-EXPIRE (CACHE KEY &KEY KEEP-FILE (KEEP-FILE NIL))

DO: Expire the entry KEY from the CACHE. KEEP-FILE: When true, the file is not deleted from the cache.

CACHE-EXPIRE-ALL (CACHE &KEY KEEP-FILES (KEEP-FILES NIL))

DO: Expire all the entries from the CACHE. KEEP-FILE: When true, the files are not deleted from the cache.

CACHE-GET (CACHE KEY)

RETURN: the value stored in the CACHE for the KEY; :FETCHED --> the value was obtained by the CACHE-PRODUCER. :IN-CORE --> the value was in memory :ON-DISK --> the value was on disk (in the disk cache).

SYNCHRONIZE-CACHE (CACHE)

DO: Ensure the cache index in core and on disk are synchronized.

Private

CACHE-INDEX-READ-DATE (CACHE)

RETURN: If the file (cache-index-file-path self) exists and is a cache index file, then the cache-date of the cache index file, else NIL.

CACHE-MAP-ENTRIES (CACHE RESULT-TYPE FUNCTION)

DO: Calls the FUNCTION on each entry of the CACHE, collecting the results in a sequence of type RESULT-TYPE. RESULT-TYPE: NIL --> no result is collected, NIL is returned. LIST --> the results are collected into a list. VECTOR --> the results are collected into a vector. STRING --> the results must be characters, they're collected into a string. RETURN: The collected results.

LOAD-CACHE (CACHE)

DO: Load the cache index from the file (cache-index-file-path self).

NEW-VALUE-FILE-PATH (CACHE)

RETURN: The file path of an new entry named NAME in the CACHE.

OLD-VALUE-FILE-PATH (CACHE NAME)

RETURN: The file path of an existing entry named NAME in the CACHE.

SAVE-CACHE (CACHE)

DO: Save the cache index to the file (cache-index-file-path self).

SET-CACHE-DIRECTORY-PATH (CACHE NEW-PATH)

DO: Change the path of the cache directory.

TOUCH-CACHE-DATE (CACHE)

DO: Update the date of the cache in core.

SLOT-ACCESSOR

Public

CACHE-DIRECTORY-PATH (CACHE)

The Path to the directory where the cache data is stored.

CACHE-INDEX-FILE-PATH (CACHE)

The RETURN: The path to the cache index file.

CACHE-PRODUCER (CACHE)

The RETURN: The cache producer of the cache.

CACHE-VALUE-FILE-TYPE (CACHE)

The RETURN: The type used for value files in the cache directory.

VARIABLE

Private

Undocumented

*TEST-CACHE*

*TEST-CACHE-2*

*TEST-COUNTER*

CLASS

Public

CACHE

A generic disk-based cache.

ENTRY

A cache index entry, mapping a key with the date the resource was fetched and the file-name of the files where the resource and the parsed html are stored, and references to these data when they are loaded in core.