Skip to content

Commit

Permalink
Merge pull request #25928 from mechanicles/info-for-cache-fetch-block
Browse files Browse the repository at this point in the history
Add proper description for `Rails.cache.fetch` [ci skip]
  • Loading branch information
prathamesh-sonpatki committed Jul 24, 2016
2 parents 7714e83 + d4f1b80 commit 56527bb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion guides/source/caching_with_rails.md
Expand Up @@ -270,7 +270,7 @@ simply be explicit in a comment, like:

Sometimes you need to cache a particular value or query result instead of caching view fragments. Rails' caching mechanism works great for storing __any__ kind of information.

The most efficient way to implement low-level caching is using the `Rails.cache.fetch` method. This method does both reading and writing to the cache. When passed only a single argument, the key is fetched and value from the cache is returned. If a block is passed, the result of the block will be cached to the given key and the result is returned.
The most efficient way to implement low-level caching is using the `Rails.cache.fetch` method. This method does both reading and writing to the cache. When passed only a single argument, the key is fetched and value from the cache is returned. If a block is passed, that block will be executed in the event of a cache miss. The return value of the block will be written to the cache under the given cache key, and that return value will be returned. In case of cache hit, the cached value will be returned without executing the block.

Consider the following example. An application has a `Product` model with an instance method that looks up the product’s price on a competing website. The data returned by this method would be perfect for low-level caching:

Expand Down

0 comments on commit 56527bb

Please sign in to comment.