Class: Bootsnap::LoadPathCache::Store
- Inherits:
-
Object
- Object
- Bootsnap::LoadPathCache::Store
- Defined in:
- lib/bootsnap/load_path_cache/store.rb
Constant Summary collapse
- VERSION_KEY =
"__bootsnap_ruby_version__"
- CURRENT_VERSION =
rubocop:disable Style/RedundantFreeze
"#{RUBY_REVISION}-#{RUBY_PLATFORM}".freeze
- NestedTransactionError =
Class.new(StandardError)
- SetOutsideTransactionNotAllowed =
Class.new(StandardError)
Instance Method Summary collapse
- #fetch(key) ⇒ Object
- #get(key) ⇒ Object
-
#initialize(store_path, readonly: false) ⇒ Store
constructor
A new instance of Store.
- #set(key, value) ⇒ Object
- #transaction ⇒ Object
Constructor Details
#initialize(store_path, readonly: false) ⇒ Store
Returns a new instance of Store.
16 17 18 19 20 21 22 |
# File 'lib/bootsnap/load_path_cache/store.rb', line 16 def initialize(store_path, readonly: false) @store_path = store_path @txn_mutex = Mutex.new @dirty = false @readonly = readonly load_data end |
Instance Method Details
#fetch(key) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bootsnap/load_path_cache/store.rb', line 28 def fetch(key) raise(SetOutsideTransactionNotAllowed) unless @txn_mutex.owned? v = get(key) unless v v = yield mark_for_mutation! @data[key] = v end v end |
#get(key) ⇒ Object
24 25 26 |
# File 'lib/bootsnap/load_path_cache/store.rb', line 24 def get(key) @data[key] end |
#set(key, value) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/bootsnap/load_path_cache/store.rb', line 40 def set(key, value) raise(SetOutsideTransactionNotAllowed) unless @txn_mutex.owned? if value != @data[key] mark_for_mutation! @data[key] = value end end |
#transaction ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/bootsnap/load_path_cache/store.rb', line 49 def transaction raise(NestedTransactionError) if @txn_mutex.owned? @txn_mutex.synchronize do yield ensure commit_transaction end end |