Sha256: a76c9c5b23330393b88f38a088b99c180f7404c9222f33610d971ca11f2aef81

Contents?: true

Size: 594 Bytes

Versions: 13

Compression:

Stored size: 594 Bytes

Contents

require "digest/md5"

module Prop
  class Key

    # Builds the expiring cache key
    def self.build(options)
      key       = options.fetch(:key)
      handle    = options.fetch(:handle)
      interval  = options.fetch(:interval)

      window    = (Time.now.to_i / interval)
      cache_key = normalize([ handle, key, window ])

      "prop/#{Digest::MD5.hexdigest(cache_key)}"
    end

    # Simple key expansion only supports arrays and primitives
    def self.normalize(key)
      if key.is_a?(Array)
        key.flatten.join("/")
      else
        key.to_s
      end
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
prop-1.1.0 lib/prop/key.rb
prop-1.0.2 lib/prop/key.rb
prop-1.0.1 lib/prop/key.rb
prop-1.0.0 lib/prop/key.rb
prop-0.7.8 lib/prop/key.rb
prop-0.7.7 lib/prop/key.rb
prop-0.7.6 lib/prop/key.rb
prop-0.7.5 lib/prop/key.rb
prop-0.7.4 lib/prop/key.rb
prop-0.7.3 lib/prop/key.rb
prop-0.7.2 lib/prop/key.rb
prop-0.7.1 lib/prop/key.rb
prop-0.7.0 lib/prop/key.rb