Class: ChefLicensing::PStoreAdapter
- Inherits:
-
Object
- Object
- ChefLicensing::PStoreAdapter
- Defined in:
- lib/chef-licensing/pstore_adapter.rb
Overview
Simple adapter to make PStore compatible with Faraday::HttpCache
Instance Method Summary collapse
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #exist?(key) ⇒ Boolean
-
#initialize(cache_dir) ⇒ PStoreAdapter
constructor
A new instance of PStoreAdapter.
-
#read(key) ⇒ Object
Interface methods required by faraday-http-cache.
- #write(key, value, options = {}) ⇒ Object
Constructor Details
#initialize(cache_dir) ⇒ PStoreAdapter
Returns a new instance of PStoreAdapter.
6 7 8 9 |
# File 'lib/chef-licensing/pstore_adapter.rb', line 6 def initialize(cache_dir) @store_path = File.join(cache_dir, "chef_licensing_cache.pstore") @store = PStore.new(@store_path) end |
Instance Method Details
#clear ⇒ Object
30 31 32 33 34 |
# File 'lib/chef-licensing/pstore_adapter.rb', line 30 def clear @store.transaction do @store.roots.each { |root| @store.delete(root) } end end |
#delete(key) ⇒ Object
22 23 24 |
# File 'lib/chef-licensing/pstore_adapter.rb', line 22 def delete(key) @store.transaction { @store.delete(key) } end |
#exist?(key) ⇒ Boolean
26 27 28 |
# File 'lib/chef-licensing/pstore_adapter.rb', line 26 def exist?(key) @store.transaction { @store.root?(key) } end |
#read(key) ⇒ Object
Interface methods required by faraday-http-cache
12 13 14 |
# File 'lib/chef-licensing/pstore_adapter.rb', line 12 def read(key) @store.transaction { @store[key] } end |
#write(key, value, options = {}) ⇒ Object
16 17 18 19 20 |
# File 'lib/chef-licensing/pstore_adapter.rb', line 16 def write(key, value, = {}) # PStore handles persistence, Faraday::HttpCache handles # HTTP cache headers for expiration @store.transaction { @store[key] = value } end |