Smalltalk/X WebserverDocumentation of class 'CacheDictionaryWithLimitedLifetime': | |||
Class: CacheDictionaryWithLimitedLifetimeInheritance:Object | +--Collection | +--Set | +--Dictionary | +--CacheDictionary | +--CacheDictionaryWithLimitedLifetime
Description:this is like a cacheDictionary (in that it keeps only a predefined, limited numer of entries) but it also 'forgets' entries after some time period. This is useful to temporarily remember eg. mime types of files or other possibly changing information which is otherwise expensive to compute. Warning: this class only supports a limited subset of the dictionary protocol; only use: at:put / at: / at:ifAbsent: / includesKey: / size [example:] |d| d := CacheDictionaryWithLimitedLifetime new:30 liveTime:3 seconds. d at:'hello' put:'world'. self assert:(d includesKey:'hello'). self assert:(d at:'hello' ifAbsent:nil) = 'world'. self assert:(d size == 1). Delay waitForSeconds:1. self assert:(d size == 1). self assert:(d at:'hello' ifAbsent:nil) = 'world'. Delay waitForSeconds:1. self assert:(d size == 1). self assert:(d at:'hello' ifAbsent:nil) = 'world'. Delay waitForSeconds:2. self assert:(d includesKey:'hello') not. self assert:(d at:'hello' ifAbsent:nil) isNil. self assert:(d size == 0). d inspect |d| d := CacheDictionaryWithLimitedLifetime new:30 liveTime:3 seconds. d reanimateOnRead:true. d at:'hello' put:'world'. self assert:(d includesKey:'hello'). self assert:(d at:'hello' ifAbsent:nil) = 'world'. self assert:(d size == 1). Delay waitForSeconds:2. self assert:(d size == 1). self assert:(d at:'hello' ifAbsent:nil) = 'world'. Delay waitForSeconds:2. self assert:(d size == 1). self assert:(d at:'hello' ifAbsent:nil) = 'world'. Delay waitForSeconds:2. self assert:(d size == 1). self assert:(d at:'hello' ifAbsent:nil) = 'world'. Delay waitForSeconds:4. self assert:(d includesKey:'hello') not. self assert:(d at:'hello' ifAbsent:nil) isNil. self assert:(d size == 0). d inspect Class protocol:instance creation
Instance protocol:accessing
Private classes:ArrayWithLimitedLiveTime |
|||
ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 16:43:58 GMT |