Sha256: 6df5aa1aefc11dfbe7bf227d8f31c281f539be18ccc1a55f0bfe50fbf2bde7db
Contents?: true
Size: 685 Bytes
Versions: 7
Compression:
Stored size: 685 Bytes
Contents
# frozen_string_literal: true module Steppy # https://github.com/jeremyevans/roda/blob/master/lib/roda.rb#L14-L42 # A thread safe cache class, offering only #[] and #[]= methods, # each protected by a mutex. class SteppyCache # Create a new thread safe cache. def initialize(hash = {}) @mutex = Mutex.new @hash = hash end # Make getting value from underlying hash thread safe. def [](key) @mutex.synchronize { @hash[key] } end # Make setting value in underlying hash thread safe. def []=(key, value) @mutex.synchronize { @hash[key] = value } end def to_h @mutex.synchronize { @hash } end end end
Version data entries
7 entries across 7 versions & 1 rubygems