|
Class: CachingRegistry
Object
|
+--Collection
|
+--Set
|
+--Dictionary
|
+--IdentityDictionary
|
+--WeakIdentityDictionary
|
+--Registry
|
+--CachingRegistry
- Package:
- stx:libbasic
- Category:
- System-Support
- Version:
- rev:
1.12
date: 2021/01/20 11:02:59
- user: cg
- file: CachingRegistry.st directory: libbasic
- module: stx stc-classLibrary: libbasic
A CachingRegistry behaves generally like a registry;
However, it keeps hard references to the last n registered objects,
preventing them from being garbage collected (and finalized).
This is useful for resources, which do not cost too much memory,
but are expensive to allocate - a special candidate of this kind are
XFonts. With a CachingRegistry, fonts are kept a bit longer alive
and can therefore often be reused - even if temporarily unreferenced.
This is kind of experimental.
[instance variables:]
keptObjects Collection hard referenced objects
cacheSize Integer number of hard references
copyrightCOPYRIGHT (c) 1999 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
instance creation
-
new: cacheSize
-
(comment from inherited method)
return a new empty Set with space for anInteger elements
enumerating
-
detect: aBlock ifNone: exceptionValue
-
... additionaly move it to the front of the LRU chain
private
-
cacheSize: aNumber
-
registering objects
-
register: anObject as: aHandle
-
(comment from inherited method)
register anObject, so that I later receive informDispose: with aHandle
(some time in the future)
-
removeKey: anObject ifAbsent: absentBlock
-
(comment from inherited method)
remove the association under aKey from the collection,
return the value previously stored there.
If it was not in the collection return the result
from evaluating aBlock.
Redefined to avoid synchronization problems, in case
of interrupts (otherwise, there could be some other operation
on the receiver done by another process, which garbles my contents).
-
safeRemoveKey: anObject
-
(comment from inherited method)
redefined to block interrupts
(avoid change of the dictionary while accessing)
|