Sha256: 3b8ae1afe0dad35e83c51ccb82b4fc516a129543e911af3d7d2da03c90017409

Contents?: true

Size: 1.1 KB

Versions: 12

Compression:

Stored size: 1.1 KB

Contents

module Plezi
   module Base
      # Provides a thread-safe caching engine
      module HasCache
         # initializes the cache
         def self.extended(base)
            base.instance_variable_set :@_lock, Mutex.new
            base.instance_variable_set :@_cache, {}.dup
         end

         # Stores data in the cache
         def store(key, value)
            @_lock.synchronize { @_cache[key] = value }
         end
         alias []= store
         # Retrieves data form the cache
         def get(key)
            @_lock.synchronize { @_cache[key] }
         end
         alias [] get
      end
      # Provides thread-specific caching engine, allowing lockless cache at the expenss of memory.
      module HasStore
         # Stores data in the cache
         def store(key, value)
            (Thread.current[(@_chache_name ||= object_id.to_s(16))] ||= {}.dup)[key] = value
         end
         alias []= store
         # Retrieves data form the cache
         def get(key)
            (Thread.current[(@_chache_name ||= object_id.to_s(16))] ||= {}.dup)[key]
         end
         alias [] get
      end
   end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
plezi-0.16.4 lib/plezi/render/has_cache.rb
plezi-0.16.3 lib/plezi/render/has_cache.rb
plezi-0.16.2 lib/plezi/render/has_cache.rb
plezi-0.16.1 lib/plezi/render/has_cache.rb
plezi-0.16.0 lib/plezi/render/has_cache.rb
plezi-0.15.1 lib/plezi/render/has_cache.rb
plezi-0.15.0 lib/plezi/render/has_cache.rb
plezi-0.14.9 lib/plezi/render/has_cache.rb
plezi-0.14.8 lib/plezi/render/has_cache.rb
plezi-0.14.7 lib/plezi/render/has_cache.rb
plezi-0.14.6 lib/plezi/render/has_cache.rb
plezi-0.14.5 lib/plezi/render/has_cache.rb