lib/dassets/cache.rb in dassets-0.14.5 vs lib/dassets/cache.rb in dassets-0.15.0

- old
+ new

@@ -1,45 +1,39 @@ -module Dassets; end -module Dassets::Cache +# frozen_string_literal: true - class MemCache - require 'thread' +require "thread" - # this is a thread-safe in-memory cache +module Dassets; end - def initialize - @hash = {} - @write_mutex = ::Mutex.new - end +# This is a thread-safe in-memory cache. +class Dassets::MemCache + def initialize + @hash = {} + @write_mutex = ::Mutex.new + end - def keys - @hash.keys - end + def keys + @hash.keys + end - def [](key) - @hash[key] - end + def [](key) + @hash[key] + end - def []=(key, value) - @write_mutex.synchronize{ @hash[key] = value } - end + def []=(key, value) + @write_mutex.synchronize{ @hash[key] = value } + end +end +# This is a no-op cache object. This is the default cache in use and "turns +# off caching. +class Dassets::NoCache + def keys + [] end - class NoCache - - # This is a no-op cache object. This is the default cache in use and "turns - # off caching. - - def keys - [] - end - - def [](key) - end - - def []=(key, value) - end - + def [](key) end + def []=(key, value) + end end