CachedValue.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 4761 6e945a9ab49d
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4759
847dd7b8f285 #DOCUMENTATION by cgexept.de
Claus Gittinger <cg@exept.de>
parents: 4758
diff changeset
     1
"{ Encoding: utf8 }"
847dd7b8f285 #DOCUMENTATION by cgexept.de
Claus Gittinger <cg@exept.de>
parents: 4758
diff changeset
     2
2835
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 2012 by eXept Software AG
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
              All Rights Reserved
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
4758
b9a20088ef47 #FEATURE by cgexept.de
Claus Gittinger <cg@exept.de>
parents: 2848
diff changeset
    16
"{ NameSpace: Smalltalk }"
b9a20088ef47 #FEATURE by cgexept.de
Claus Gittinger <cg@exept.de>
parents: 2848
diff changeset
    17
2835
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
Object subclass:#CachedValue
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:'value expirationTime computation validityDuration'
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:''
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	category:'Kernel-Processes'
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
NotFoundError subclass:#ValueExpiredException
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
	instanceVariableNames:''
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
	classVariableNames:''
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
	poolDictionaries:''
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
	privateIn:CachedValue
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
!
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
!CachedValue class methodsFor:'documentation'!
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
copyright
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
"
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 COPYRIGHT (c) 2012 by eXept Software AG
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
              All Rights Reserved
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
 This software is furnished under a license and may be used
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
 only in accordance with the terms of that license and with the
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
 inclusion of the above copyright notice.   This software may not
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
 be provided or otherwise made available to, or used by, any
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
 other person.  No title to or ownership of the software is
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
 hereby transferred.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
"
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
!
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
documentation
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
"
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    Instances of CachedValue can be used for values which are costly to evaluate,
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    but which can be cached for some time. 
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    For example, when asking a source code repository for the set of symbolic names,
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    this query takes a few seconds (a CVS roundtrip). However, this information can easily
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    be cached and remembered for some time (say 30seconds or so), to speed up followup
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    repository operations.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
    You may find more similar uses of this class.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
    [author:]
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
        Claus Gittinger
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
    [instance variables:]
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
        value ..................... the computed (cached value)
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
        expirationTime ............ timeStamp, when this value becomes obsolete
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
        validDuration ............. timeDuration, how long a computed value remains valid
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
        computation ............... a computation block, to recompute the value.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
    [class variables:]
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    [see also:]
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
"
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
!
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
examples
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
"
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
                                                                        [exBegin]
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
        |cv exceptionRaised didCompute|
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
        didCompute := false.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
        cv := CachedValue compute:[didCompute := true. Date today dayOfWeek] validityDuration:(2 seconds).
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
        self assert:(cv isValid not).
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
        self assert:(didCompute not).
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
        self assert:(cv value = Date today dayOfWeek).
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
        self assert:(cv isValid).
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
        self assert:(didCompute).
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
        Delay waitForSeconds:3.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
        didCompute := false.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
        self assert:(cv isValid not).
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
        self assert:(didCompute not).
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
        self assert:(cv value = Date today dayOfWeek).
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
        self assert:(cv isValid).
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
        self assert:(didCompute).
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
                                                                        [exEnd]
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
                                                                        [exBegin]
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
        |cv exceptionRaised|
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
        cv := CachedValue value:123 expirationTime:(Timestamp now + 2 seconds).
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
        self assert:(cv isValid).
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
        Delay waitForSeconds:3.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
        self assert:(cv isValid not).
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
        exceptionRaised := false.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
        ValueExpiredException handle:[:ex |
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
            exceptionRaised := true.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
        ] do:[
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
            cv value
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
        ].
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
        self assert:exceptionRaised.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
                                                                        [exEnd]
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
"
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
! !
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
!CachedValue class methodsFor:'instance creation'!
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
compute:actionBlock validityDuration:aTimeduration
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
    "return a 'self computing' cachedvalue, which ceases to be valid aTimeduration after
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
     it has computed its value. 
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
     If asked again for a value, it will automatically recompute the value."
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
    ^ self new 
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
        compute:actionBlock validityDuration:aTimeduration
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
!
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
value:valueArg expirationTime:aTimestamp
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
    "return a 'one shot' cachedValue, which ceases to be valid at expirationTime.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
     If asked for the value after that, an exception is raised
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
     (i.e. it does not automatically recompute a value)"
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
    ^ self new 
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
        value:valueArg expirationTime:aTimestamp
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
! !
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
!CachedValue methodsFor:'accessing'!
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
compute:computationBlock validityDuration:aTimeduration
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
    computation := computationBlock.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
    validityDuration := aTimeduration
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
!
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
expirationTime:something
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
    expirationTime := something.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
!
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
4758
b9a20088ef47 #FEATURE by cgexept.de
Claus Gittinger <cg@exept.de>
parents: 2848
diff changeset
   145
forceInvalid
4761
6e945a9ab49d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4759
diff changeset
   146
    expirationTime := nil
6e945a9ab49d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4759
diff changeset
   147
6e945a9ab49d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4759
diff changeset
   148
    "Modified: / 05-11-2018 / 12:48:00 / Claus Gittinger"
4758
b9a20088ef47 #FEATURE by cgexept.de
Claus Gittinger <cg@exept.de>
parents: 2848
diff changeset
   149
!
b9a20088ef47 #FEATURE by cgexept.de
Claus Gittinger <cg@exept.de>
parents: 2848
diff changeset
   150
2835
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
value
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
    "return my value. If not yet computed or expired, recompute using the computation block.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
     Otherwise return the cacehdValue"
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
    self isValid ifFalse:[
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
        validityDuration isNil ifTrue:[
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
            ValueExpiredException raiseRequestWith:self.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
            ^ nil
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
        ].
2848
a37eab3ef557 changed:
Claus Gittinger <cg@exept.de>
parents: 2847
diff changeset
   160
        self computeCachedValue.
2835
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
    ].
2848
a37eab3ef557 changed:
Claus Gittinger <cg@exept.de>
parents: 2847
diff changeset
   162
    ^ value
2835
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
!
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
value:valueArg expirationTime:aTimestamp
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
    value := valueArg.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
    expirationTime := aTimestamp
2847
7a563655c3b6 added: #valueOrIfInvalid:
Claus Gittinger <cg@exept.de>
parents: 2835
diff changeset
   168
!
7a563655c3b6 added: #valueOrIfInvalid:
Claus Gittinger <cg@exept.de>
parents: 2835
diff changeset
   169
7a563655c3b6 added: #valueOrIfInvalid:
Claus Gittinger <cg@exept.de>
parents: 2835
diff changeset
   170
valueOrIfInvalid:exceptionalValue
7a563655c3b6 added: #valueOrIfInvalid:
Claus Gittinger <cg@exept.de>
parents: 2835
diff changeset
   171
    "return my value, if valid. Otherwise, return the value from exceptionalValue."
7a563655c3b6 added: #valueOrIfInvalid:
Claus Gittinger <cg@exept.de>
parents: 2835
diff changeset
   172
7a563655c3b6 added: #valueOrIfInvalid:
Claus Gittinger <cg@exept.de>
parents: 2835
diff changeset
   173
    self isValid ifFalse:[^ exceptionalValue value].
2848
a37eab3ef557 changed:
Claus Gittinger <cg@exept.de>
parents: 2847
diff changeset
   174
    ^ value
2835
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
! !
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
!CachedValue methodsFor:'private'!
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
computeCachedValue
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
    expirationTime := Timestamp now + validityDuration.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
    value := computation value.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
! !
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
!CachedValue methodsFor:'queries'!
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
isValid
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
    "true if the cached value is still valid"
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
    expirationTime notNil ifTrue:[
4759
847dd7b8f285 #DOCUMENTATION by cgexept.de
Claus Gittinger <cg@exept.de>
parents: 4758
diff changeset
   190
        Timestamp now < expirationTime ifTrue:[
2835
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
            ^ true
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
        ].
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
        expirationTime := nil.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
    ].
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
    ^ false
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
! !
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
!CachedValue::ValueExpiredException class methodsFor:'documentation'!
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
documentation
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
"
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
    raised when a cachedValue has expired
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
"
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
! !
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
!CachedValue::ValueExpiredException class methodsFor:'initialization'!
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
initialize
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
    NotifierString := 'value expired'.
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
! !
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
!CachedValue class methodsFor:'documentation'!
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
version
4758
b9a20088ef47 #FEATURE by cgexept.de
Claus Gittinger <cg@exept.de>
parents: 2848
diff changeset
   215
    ^ '$Header$'
2835
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
!
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
version_CVS
4758
b9a20088ef47 #FEATURE by cgexept.de
Claus Gittinger <cg@exept.de>
parents: 2848
diff changeset
   219
    ^ '$Header$'
2835
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
! !
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
4758
b9a20088ef47 #FEATURE by cgexept.de
Claus Gittinger <cg@exept.de>
parents: 2848
diff changeset
   222
2835
88ddcdf93432 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
CachedValue::ValueExpiredException initialize!