CDLRUCache.mesa a ChipNDale module
Copyright © 1983, 1985 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi September 19, 1985 3:15:21 am PDT
Last edited by: Christian Jacobi, September 19, 1986 10:05:20 am PDT
DIRECTORY
CD;
CDLRUCache: CEDAR DEFINITIONS =
BEGIN
Implementing a last recently used cache of object. This is for the benefit of technology implementors only. Caching must only be used for immutable objects; cached objects may appear in multiple designs.
LRUCache: TYPE = REF LRUCacheRep;
LRUCacheRep: TYPE;
AequivalenceProc: TYPE = PROC[mySpecific, other: REF ANY] RETURNS [BOOL];
NewProc: TYPE = PROC [] RETURNS [CD.Object];
Create: PROC [size: CARDINAL ← 17, aequivalenceProc: AequivalenceProc←NIL, newProc: NewProc←NIL] RETURNS [LRUCache];
--creates new LRU cache of suggested size
--aequivalenceProc: procedure to check specificRef's for aequivalence
--  NIL means: aeqivalence if same REF's
--newProc: Procedure to allocate new objects;
--  NIL means: UnusedOrNew will never be called on this LRUCache
UnusedOrNew: PROC [lruCache: LRUCache] RETURNS [CD.Object];
--this procedure is defined only if Create of lruCache had a NewProc
--before allocating a new object with the newProc, it tries if
ReplaceByAequivalent: PROC [lruCache: LRUCache, ob: CD.Object] RETURNS [CD.Object];
--returns either "ob" or an aequivalent object to "ob"
--side effect: introduces "ob" in aequivalence table to be accessed by others.
--consider "ob" immutable! respectively, on any further change, it may cause
--the same change made to all or some aequivalent objects in past and future
END.