eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'CacheDictionaryWithFactory':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: CacheDictionaryWithFactory


Inheritance:

   Object
   |
   +--Collection
      |
      +--Set
         |
         +--Dictionary
            |
            +--CacheDictionary
               |
               +--CacheDictionaryWithFactory

Package:
stx:libbasic2
Category:
Collections-Unordered
Version:
rev: 1.5 date: 2021/12/04 07:30:33
user: cg
file: CacheDictionaryWithFactory.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


like a Dictionary, but does not grow beyond a given max. size
(i.e. only keeps size items),
It can be used as a cache, for keeping recently used objects alive.
Must be created with an initial (=maximal) size. 
In addition to the normal CacheDictionary behavior, 
this also keeps a factoryBlock to automatically compute missing elements.

copyright

COPYRIGHT (c) 2003 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.

Class protocol:

instance creation
o  new: cacheSize factory: aBlock


Instance protocol:

accessing
o  at: key
(comment from inherited method)
return the element indexed by aKey - report an error if none found

initialization
o  factory: aBlock


Examples:


caches reverse strings (stupid usage)
  |c|

  c := CacheDictionaryWithFactory
          new:100 factory:[:key | key reversed].

  c at:'hello'.
  c at:'hello'.
  1 to:1000 do:[:i | c at:i printString].
  c at:'hello'.
Test: should halt (compute 'hello') only twice.
  |c numHalts|

  numHalts := 0.

  c := CacheDictionaryWithFactory
          new:100 factory:[:key | key = 'hello' ifTrue:[numHalts := numHalts + 1]. key reversed].

  c at:'hello'.
  c at:'hello'.
  1 to:1000 do:[:i | c at:i printString].
  c at:'hello'.
  self assert:( numHalts == 2 ).


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sun, 16 Jun 2024 03:48:41 GMT