caching - How does Rails generate the view cache key? -
I was always wondering how the rail generates cache and, in particular, does:
users.concat (@products) / Pre>
method is:
increases the # key + argument Which can be used for the #cache store, optionally accepts a namespace, and all the keys are scanned within that namespace. Or. # # If the + key + argument is provided then there is an array, or responds to + to_a +, then # each element will be converted into an array / key and # will be added together in singles for example: ## expand_cache_key ([: foo,: bar]) # = & gt; "Foo / bar" # expand_cache_key ([: foo,: bar], "namespace") # = & gt; "Namespace / Foo / Bar" # # + + + key + logic can also respond to + cache_key + or + to_param +. Def extension_cache_key (key, namespace = zero) expanded_cache_key = namespace? "# {Namesphere} /": "" If Prefix = INV ["RailSecCIIDID"]] || ENV ["RAILS_APP_VERSION"] expanded_cache_key & lt; & Lt; "# {Prefix} /" extended_shade_shadowed left; & Lt; Retrieve_cache_key (key) expanded_cache_key end
Let's define a shortcut:
def cache (* args); ActiveSupport :: Cache.expand_cache_key (* args);
For more readability:
ENV ["RAILS_CACHE_ID"] = ''
So it is recursive , For example:
cache 'string' = & gt; "/ String" cache [1, 2] = & gt; "/ 1/2" cache [1, 2, 3, 4] = & gt; "/ 1/2/3/4" cache [1, 2], [3, 4] => "[3, 4] // 1/2" cache [[1, 2], [3, 4]] => "/ 1/2/3/4" cache [@user, @products] = & gt; "/ Users / 207311-20140409135446308087000 / user / 207312-20140401185427926822000 / products / 1-20130531221550045078000 / products / 2-20131109180059828964000 / products / 1-20130531221550045078000 / products / 2-20131109180059828964000" Cash @ users.concat (@products) = & gt ; "/ User / 207311-20140409135446308087000 / user / 207312-20140401185427926822000/products/1-20130531221550045078000/products/2-20131109180059828964000/products/1-20130531221550045078000/products/2-20131109180059828964000"
of As you can see, the second parameter is a namespace, so always keep your criteria in the array .
So to answer my question, this is the same.
Comments
Post a Comment