Sha256: 386dbd9c891da5ae37c2e05e37acabaf28af30aea5392255399dbfaf919215cd

Contents?: true

Size: 859 Bytes

Versions: 7

Compression:

Stored size: 859 Bytes

Contents

require 'thread'

# this is a thread-safe in-memory cache for use with the `SourceCache` that
# only caches source fingerprint keys.  there are a few reasons for using this
# as the "default":
# * source fingerprints are accessed more frequently than contents (ie hrefs,
#   urls, etc) so caching them can have nice affects on performance.  Plus it
#   seems silly to have to compile the source file everytime you want to get its
#   href so you can link it in.
# * fingerprints have a much smaller data size so won't overly bloat memory.

class Dassets::DefaultCache

  def initialize
    @hash = {}
    @write_mutex = ::Mutex.new
  end

  def keys;    @hash.keys; end
  def [](key); @hash[key]; end

  def []=(key, value)
    @write_mutex.synchronize do
      @hash[key] = value if key =~ /-- fingerprint$/ # only write fingerprint keys
    end
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dassets-0.7.0 lib/dassets/default_cache.rb
dassets-0.6.2 lib/dassets/default_cache.rb
dassets-0.6.1 lib/dassets/default_cache.rb
dassets-0.6.0 lib/dassets/default_cache.rb
dassets-0.5.0 lib/dassets/default_cache.rb
dassets-0.4.1 lib/dassets/default_cache.rb
dassets-0.4.0 lib/dassets/default_cache.rb