Class: Ferret::Search::CachingWrapperFilter
- Defined in:
- lib/ferret/search/caching_wrapper_filter.rb
Overview
Wraps another filter’s result and caches it. The caching behavior is like QueryFilter. The purpose is to allow filters to simply filter, and then wrap with this class to add caching, keeping the two concerns decoupled yet composable.
Instance Method Summary collapse
- #bits(reader) ⇒ Object
-
#initialize(filter) ⇒ CachingWrapperFilter
constructor
- filter
-
Filter to cache results of.
- #to_s ⇒ Object
Constructor Details
#initialize(filter) ⇒ CachingWrapperFilter
- filter
-
Filter to cache results of
10 11 12 13 |
# File 'lib/ferret/search/caching_wrapper_filter.rb', line 10 def initialize(filter) @filter = filter @cache = nil end |
Instance Method Details
#bits(reader) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ferret/search/caching_wrapper_filter.rb', line 15 def bits(reader) if (@cache == nil) @cache = Ferret::Utils::WeakKeyHash.new end @cache.synchronize() do # check cache bits = @cache[reader] if bits return bits end end bits = @filter.bits(reader) @cache.synchronize() do # update cache @cache[reader] = bits end return bits end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/ferret/search/caching_wrapper_filter.rb', line 36 def to_s() return "CachingWrapperFilter(#{@filter})" end |