Sha256: a212a00498299c43f99ec04a57045ddc3e6dc1e3f1318a6ace9bb2a413ccca28
Contents?: true
Size: 1.28 KB
Versions: 6
Compression:
Stored size: 1.28 KB
Contents
require "digest/sha2" module InfoparkComponentCache module KeyGenerator # @author Tomasz Przedmojski <tomasz.przedmojski@infopark.de> # # Generates a key identifing an Object # # @param [#cache_key, #to_param] anything 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 # @return [String] string that does not contain file-system insecure characters (\, / etc.) def self.generate_key(anything) encode_key(Rails.cache.send(:expanded_key, anything)) end # 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) # # @param [String] string input string to be encoded # @return [String] string that is guaranteed to # consist only of alphanumeric characters, # and not to exceed 100 characters def self.encode_key(string) #:nodoc: Digest::SHA2.hexdigest(string) end end end
Version data entries
6 entries across 6 versions & 1 rubygems