Class: OpenWFE::CacheExpressionStorage
- Inherits:
-
Object
- Object
- OpenWFE::CacheExpressionStorage
- Includes:
- ExpressionStorageBase, OwfeServiceLocator, ServiceMixin
- Defined in:
- lib/openwfe/expool/expstorage.rb
Overview
This cache uses a LruHash (Least Recently Used) to store expressions. If an expression is not cached, the ‘real storage’ is consulted. The real storage is supposed to be the service named “expressionStorage.1”
Constant Summary collapse
- MIN_SIZE =
under 20 stored expressions, the unit tests for the CachedFilePersistedEngine do fail because the persistent storage behind the cache hasn’t the time to flush its work queue. a min size limit has been set to 77.
77- DEFAULT_SIZE =
5000
Instance Attribute Summary
Attributes included from ServiceMixin
Attributes included from Contextual
Instance Method Summary collapse
- #[](fei) ⇒ Object
- #[]=(fei, fe) ⇒ Object
- #clear ⇒ Object (also: #purge)
- #delete(fei) ⇒ Object
-
#fetch_root(wfid) ⇒ Object
Attempts at fetching the root expression of a given process instance.
-
#find_expressions(options = {}) ⇒ Object
This implementations of find_expressions() immediately passes the call to the underlying real storage.
-
#initialize(service_name, application_context) ⇒ CacheExpressionStorage
constructor
A new instance of CacheExpressionStorage.
- #length ⇒ Object (also: #size)
Methods included from ExpressionStorageBase
#class_accepted?, #does_match?, #observe_expool, #to_s
Methods included from OwfeServiceLocator
#get_engine, #get_error_journal, #get_expool, #get_expression_map, #get_expression_pool, #get_expression_storage, #get_expression_storages, #get_journal, #get_participant_map, #get_scheduler, #get_wfid_generator
Methods included from ServiceMixin
Methods included from Contextual
#get_work_directory, #init_service, #lookup
Methods included from Logging
#ldebug, #ldebug_callstack, #lerror, #lfatal, #linfo, #llog, #lunknown, #lwarn
Constructor Details
#initialize(service_name, application_context) ⇒ CacheExpressionStorage
Returns a new instance of CacheExpressionStorage.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/openwfe/expool/expstorage.rb', line 192 def initialize (service_name, application_context) super() service_init(service_name, application_context) size = @application_context[:expression_cache_size] || DEFAULT_SIZE size = MIN_SIZE unless size > MIN_SIZE linfo { "new() size is #{size}" } @cache = LruHash.new(size) @real_storage = nil observe_expool end |
Instance Method Details
#[](fei) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/openwfe/expool/expstorage.rb', line 210 def [] (fei) #ldebug { "[] size is #{@cache.size}" } #ldebug { "[] (sz #{@cache.size}) for #{fei.to_debug_s}" } fe = @cache[fei.hash] return fe if fe #ldebug { "[] (reload) for #{fei.to_debug_s}" } fe = get_real_storage[fei] unless fe #ldebug { "[] (reload) miss for #{fei.to_debug_s}" } return nil end @cache[fei.hash] = fe fe end |
#[]=(fei, fe) ⇒ Object
232 233 234 235 236 237 |
# File 'lib/openwfe/expool/expstorage.rb', line 232 def []= (fei, fe) ldebug { "[]= caching #{fei}" } @cache[fei.hash] = fe end |
#clear ⇒ Object Also known as: purge
251 252 253 254 |
# File 'lib/openwfe/expool/expstorage.rb', line 251 def clear @cache.clear end |
#delete(fei) ⇒ Object
239 240 241 242 |
# File 'lib/openwfe/expool/expstorage.rb', line 239 def delete (fei) @cache.delete fei.hash end |
#fetch_root(wfid) ⇒ Object
Attempts at fetching the root expression of a given process instance.
271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/openwfe/expool/expstorage.rb', line 271 def fetch_root (wfid) # # at first, look in the cache @cache.each do |hashed_fei, fexp| return fexp \ if fexp.fei.wfid == wfid and fexp.is_a?(DefineExpression) end get_real_storage.fetch_root wfid end |
#find_expressions(options = {}) ⇒ Object
This implementations of find_expressions() immediately passes the call to the underlying real storage.
262 263 264 265 |
# File 'lib/openwfe/expool/expstorage.rb', line 262 def find_expressions (={}) get_real_storage.find_expressions end |
#length ⇒ Object Also known as: size
244 245 246 247 |
# File 'lib/openwfe/expool/expstorage.rb', line 244 def length @cache.length end |