FunctionCache: CEDAR DEFINITIONS ~ BEGIN Cache: TYPE ~ REF CacheRep; CacheInfo: TYPE ~ RECORD [nEntries: INT, maxEntries: INT, totalSize: INT, maxTotalSize: INT]; Create: PROC [maxEntries: INT _ 10, maxTotalSize: INT _ INT.LAST] RETURNS [Cache]; ClientID: TYPE ~ REF; -- to allow otherwise independent clients to share cache space. Domain: TYPE ~ REF; Range: TYPE ~ REF; Eval: PROC [x: Cache, F: FuncProc, arg: Domain, match: Match, clientID: ClientID _ NIL] RETURNS [Range]; FuncProc: TYPE ~ PROC [Domain] RETURNS [value: Range, size: INT]; Match: TYPE ~ {refs, case, text} _ refs; Insert: PROC [x: Cache, argument: Domain, value: Range, size: INT, clientID: ClientID _ NIL]; CompareProc: TYPE ~ PROC [argument: Domain] RETURNS [good: BOOL]; Any: CompareProc; -- returns TRUE Equal: PROC [a, b: Domain, match: Match] RETURNS [BOOL]; Lookup: PROC [x: Cache, compare: CompareProc, clientID: ClientID _ NIL] RETURNS [value: Range, ok: BOOL]; CacheEntry: TYPE ~ RECORD [clientID: ClientID, argument: Domain, value: Range, size: INT]; Obtain: PROC [x: Cache, compare: CompareProc, limit: INT _ 1, clientID: ClientID _ NIL] RETURNS [LIST OF CacheEntry]; Release: PROC [x: Cache, list: LIST OF CacheEntry]; GetInfo: PROC [x: Cache] RETURNS [CacheInfo]; GetList: PROC [x: Cache] RETURNS [LIST OF CacheEntry]; SetLimits: PROC [x: Cache, maxEntries: INT _ 10, maxTotalSize: INT _ INT.LAST]; SetValueSize: PROC [x: Cache, value: Range, size: INT]; GlobalCache: PROC RETURNS [Cache]; CacheRep: TYPE ~ PRIVATE MONITORED RECORD [ nEntries: INT, maxEntries: INT, totalSize: INT, maxTotalSize: INT, entryList: LIST OF CacheEntry ]; END. ΰFunctionCache.mesa Michael Plass, June 19, 1985 9:42:48 pm PDT Copyright c 1985 by Xerox Corporation. All rights reserved. Documentation: This module provides a facility for writing cached implementations of REF-valued functions. The caches are managed with a move-to-front discipline, and trimmed according to the client supplied limits on the total number of entries or the total number of words consumed. This is a convenience when the client already has an argument REF allocated; use the Lookup proc, below, to do more general matching or to avoid early argument allocation. refs ~ ref equality case ~ understands REF INT, REF REAL, REF CHAR, LIST OF REF, ROPE, ATOM; otherwise uses ref equality text ~ like above, but ignores case on REF CHARs, ATOMs and ROPEs The fancy compare used by Eval; Allows client to inspect each entry that matches clientID and decide if it meets the requirements; compare is called under a monitor, so make sure it is bulletproof. If compare returns TRUE for some entry, Lookup returns the value of that entry with ok=TRUE; otherwise returns [NIL, FALSE]. Gains exclusive use of the entries by removing them from the cache. The result has no more than n entries. Puts the entries back in the cache. Copies the list under the monitor. Use this for applications where the entry sizes are large, so that all such clients can compete fairly for the available memory. Use individual caches when the entries are small; this will keep the cache lookup time down. ΚL˜™Icode™+Kšœ Οmœ1™Ÿœj™«Kš œ ŸœŸœ ŸœŸœ˜AšœŸœ˜(Kšœ™KšœŸœŸœŸœŸœŸœŸœŸœŸœŸœŸœŸœ™dKšœA™A—K˜—š œŸœ2ŸœŸœ˜]K˜—Kš œ ŸœŸœŸœŸœ˜AKš œ‘˜!š œŸœŸœŸœ˜8Kšœ™K˜—š  œŸœ7ŸœŸœŸœ˜iKš œΊŸœ@ŸœŸœŸœ™£K˜—šœ ŸœŸœ<Ÿœ˜ZK˜—š œŸœ)ŸœŸœŸœŸœŸœ ˜uK™kK™—š œŸœŸœŸœ ˜3K™#K˜—š œŸœ Ÿœ ˜-K˜—š  œŸœ ŸœŸœŸœ ˜6K™"K˜—š   œŸœŸœŸœŸœŸœ˜OK˜—š  œŸœ Ÿœ˜7K˜—š  œŸœŸœ ˜"K™ήK˜—š œ ŸœŸœŸ œŸœ˜+Kšœ Ÿœ˜Kšœ Ÿœ˜Kšœ Ÿœ˜KšœŸœ˜Kšœ ŸœŸœ ˜Kšœ˜——K˜KšŸœ˜—…—h”