Class: RSpec::Puppet::Cache
- Inherits:
-
Object
- Object
- RSpec::Puppet::Cache
- Defined in:
- lib/rspec-puppet/cache.rb
Constant Summary collapse
- MAX_ENTRIES =
16
Instance Method Summary collapse
- #get(*args, &blk) ⇒ Object
-
#initialize(&default_proc) ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize(&default_proc) ⇒ Cache
Returns a new instance of Cache.
7 8 9 10 11 |
# File 'lib/rspec-puppet/cache.rb', line 7 def initialize(&default_proc) @default_proc = default_proc @cache = {} @lra = [] end |
Instance Method Details
#get(*args, &blk) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rspec-puppet/cache.rb', line 13 def get(*args, &blk) # decouple the hash key from whatever the blk might do to it key = Marshal.load(Marshal.dump(args)) if !@cache.has_key? key @cache[key] = (blk || @default_proc).call(*args) @lra << key expire! end @cache[key] end |