Module: InfoparkComponentCache::KeyGenerator

Defined in:
lib/infopark_component_cache/key_generator.rb

Class Method Summary collapse

Class Method Details

.encode_key(string) ⇒ String

Encodes a provided key yielding a string that only consists of alphanumeric characters of limited length. Underlying implementation uses some kind of hashing algorithm and therefore has the same characteristics: equal inputs yield equal outputs, but different inputs can yield same outputs (although it is very very unlikely)

Parameters:

  • string (String)

    input string to be encoded

Returns:

  • (String)

    string that is guaranteed to consist only of alphanumeric characters, and not to exceed 100 characters



27
28
29
# File 'lib/infopark_component_cache/key_generator.rb', line 27

def self.encode_key(string) #:nodoc:
  Digest::SHA2.hexdigest(string)
end

.generate_key(anything) ⇒ String

Generates a key identifing an Object

Parameters:

  • anything (#cache_key, #to_param)

    an Object that responds to #cache_key. It is assumed that calls to #cache_key produce consistent and deterministic results. Futhermore for no two distinct objects should their #cache_key be equal

Returns:

  • (String)

    string that does not contain file-system insecure characters (, / etc.)

Author:



13
14
15
# File 'lib/infopark_component_cache/key_generator.rb', line 13

def self.generate_key(anything)
  encode_key(Rails.cache.send(:expanded_key, anything))
end