Sha256: 6049a8576995f9a8879ba92aad3e13f97b95a92c00868e7c85a868966574961a

Contents?: true

Size: 865 Bytes

Versions: 1

Compression:

Stored size: 865 Bytes

Contents

require 'coin'
require 'digest'
require 'singleton'

module Shhh
  module App
    #
    # +Cache+ looks like a hash, but is a singleton, and provides
    # access to the shared across processes Cache.
    #
    # The current implementation is based on DRb, which creates a
    # server process that then manages the data structure.
    #
    class Cache
      include Singleton

      class << self
        def cache
          self.instance
        end

        def configure
          # configure the URI that the DRb server runs on
          Coin.uri = 'druby://127.0.0.1:24924'
        end
      end

      self.configure

      def [] (key)
        Coin.read(md5(key))
      end

      def []=(key, value)
        Coin.write(md5(key), value)
      end

      private

      def md5(string)
        Digest::MD5.base64digest(string)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shhh-1.6.5 lib/shhh/app/cache.rb