README.md in second_level_cache-2.2.6 vs README.md in second_level_cache-2.3.0.beta

- old
+ new

@@ -38,11 +38,11 @@ For example, cache User objects: ```ruby class User < ActiveRecord::Base - acts_as_cached(version: 1, expires_in: 1.week) + second_level_cache expires_in: 1.week end ``` Then it will fetch cached object in this situations: @@ -65,11 +65,13 @@ ```ruby user = User.find(1) user.expire_second_level_cache ``` + or expires cache using class method: + ```ruby User.expire_second_level_cache(1) ``` Disable SecondLevelCache: @@ -95,19 +97,19 @@ * SecondLevelCache sync cache after transaction commit: ```ruby # user and account's write_second_level_cache operation will invoke after the logger. ActiveRecord::Base.transaction do - user.save - account.save - Rails.logger.info "info" + user.save + account.save + Rails.logger.info "info" end # <- Cache write # if you want to do something after user and account's write_second_level_cache operation, do this way: ActiveRecord::Base.transaction do - user.save - account.save + user.save + account.save end # <- Cache write Rails.logger.info "info" ``` * If you are using SecondLevelCache with database_cleaner, you should set cleaning strategy to `:truncation`: @@ -117,31 +119,34 @@ ``` ## Configure In production env, we recommend to use [Dalli](https://github.com/mperham/dalli) as Rails cache store. + ```ruby - config.cache_store = [:dalli_store, APP_CONFIG["memcached_host"], { namespace: "ns", compress: true }] +config.cache_store = [:dalli_store, APP_CONFIG["memcached_host"], { namespace: "ns", compress: true }] ``` ## Tips: * When you want to clear only second level cache apart from other cache for example fragment cache in cache store, you can only change the `cache_key_prefix`: ```ruby SecondLevelCache.configure.cache_key_prefix = "slc1" ``` -* When schema of your model changed, just change the `version` of the speical model, avoding clear all the cache. +* SecondLevelCache was added model schema digest as cache version, this means when you add/remove/change columns, the caches of this Model will expires. +* When your want change the model cache version by manualy, just add the `version` option like this: + ```ruby class User < ActiveRecord::Base - acts_as_cached(version: 2, expires_in: 1.week) + second_level_cache version: 2, expires_in: 1.week end ``` -* It provides a great feature, not hits db when fetching record via unique key(not primary key). +* It provides a great feature, not hits db when fetching record via unique key (not primary key). ```ruby # this will fetch from cache user = User.fetch_by_uniq_keys(nick_name: "hooopo") post = Post.fetch_by_uniq_keys(user_id: 2, slug: "foo") @@ -154,9 +159,10 @@ ```ruby Answer.includes(:question).limit(10).order("id DESC").each{|answer| answer.question.title} Answer Load (0.2ms) SELECT `answers`.* FROM `answers` ORDER BY id DESC LIMIT 10 # Only one SQL query and one Rails.cache.read_multi fetching operation. ``` + [Details for read_multi feature](http://hooopo.writings.io/articles/a9cae5e0). ## Contributors * [chloerei](https://github.com/chloerei)