lib/openwfe/expool/expstorage.rb in openwferu-0.9.11 vs lib/openwfe/expool/expstorage.rb in openwferu-0.9.12
- old
+ new
@@ -46,11 +46,11 @@
require 'openwfe/service'
require 'openwfe/util/lru'
require 'openwfe/flowexpressionid'
module OpenWFE
-
+
#
# 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"
@@ -100,11 +100,11 @@
def [] (fei)
#ldebug { "[] size is #{@cache.size}" }
#ldebug { "[] (sz #{@cache.size}) for #{fei.to_debug_s}" }
- fe = @cache[fei]
+ fe = @cache[fei.hash]
return fe if fe
ldebug { "[] (reload) for #{fei.to_debug_s}" }
fe = get_real_storage[fei]
@@ -112,21 +112,21 @@
unless fe
#ldebug { "[] (reload) miss for #{fei.to_debug_s}" }
return nil
end
- @cache[fei] = fe
+ @cache[fei.hash] = fe
return fe
end
def []= (fei, fe)
- @cache[fei] = fe
+ @cache[fei.hash] = fe
end
def delete (fei)
- @cache.delete(fei)
+ @cache.delete fei.hash
end
def length
@cache.length
end
@@ -146,31 +146,40 @@
def each_of_kind (kind, &block)
get_real_storage.each_of_kind(kind, &block)
end
- def each (&block)
- #@cache.each do |k, v|
- # block.call(k, v)
- #end
- @cache.each(&block)
+ #
+ # Passes a block to the expressions currently in the cache.
+ #
+ def each (wfid_prefix=nil, &block)
+
+ #@cache.each(&block)
+
+ if wfid_prefix
+ @cache.each do |fei, fexp|
+ next unless fei.wfid.match "^#{wfid_prefix}"
+ block.call fei, fexp
+ end
+ else
+ @cache.each(&block)
+ end
end
#
# This each() just delegates to the real storage each() method.
#
- def real_each (&block)
- #@cache.each do |k, v|
- # block.call(k, v)
- #end
- get_real_storage.each(&block)
+ def real_each (wfid_prefix=nil, &block)
+
+ get_real_storage.each(wfid_prefix, &block)
end
#
# Displays a human-friendly view on this storage
#
def to_s
+
expstorage_to_s(self)
end
protected
@@ -207,30 +216,57 @@
#ldebug { ":update for #{fei}" }
self[fei] = fe
end
get_expression_pool.add_observer(:remove) do |channel, fei|
#ldebug { ":delete for #{fei}" }
- self.delete(fei)
+ self.delete fei
end
end
+ #def []= (fei, fe)
+ # super fei.hash, fe
+ #end
+ #def [] (fei)
+ # super fei.hash
+ #end
+ #def delete (fei)
+ # super fei.hash
+ #end
+
alias :purge :clear
+ #
+ # Allows to pass a block to each expressions of a given kind (type).
+ #
def each_of_kind (kind, &block)
return unless block
self.each_value do |fexp|
- block.call(fexp) if fexp.kind_of? kind
+ block.call(fexp) if fexp.kind_of?(kind)
end
end
+ def each (wfid_prefix=nil, &block)
+
+ if wfid_prefix
+
+ super() do |fei, fexp|
+ next unless fei.wfid.match "^#{wfid_prefix}"
+ block.call fei, fexp
+ end
+ else
+
+ super(&block)
+ end
+ end
+
def to_s
expstorage_to_s(self)
end
alias :real_each :each
-
+
end
#
# a small help method for expression storages...
#