Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06143af
commit c2dde7e
Showing
8 changed files
with
75 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ rvm: | |
- ree | ||
- 1.9.2 | ||
- 1.9.3 | ||
services: | ||
- memcached |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
module CacheMetaInfo::MemCacheStore | ||
def append_cached_key(key) | ||
cached_keys | ||
@need_append ||= !Rails.cache.write(key_for_cached_keys, key, | ||
:raw => true, | ||
:unless_exist => true ) | ||
if @need_append and not cached_keys.include?(key) | ||
cached_keys << key | ||
Rails.cache.append(key_for_cached_keys, ",#{key}") | ||
module SuperCache | ||
module CacheMetaInfo | ||
module MemCacheStore | ||
def append_cached_key(key) | ||
cached_keys | ||
@need_append ||= !Rails.cache.write(key_for_cached_keys, key, | ||
:raw => true, | ||
:unless_exist => true ) | ||
Rails.cache.append(key_for_cached_keys, ",#{key}") if @need_append and not cached_keys.include?(key) | ||
cached_keys << key | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
module CacheMetaInfo::RedisStore | ||
def append_cached_key(key) | ||
cached_keys << key | ||
end | ||
def clear_related_caches | ||
cached_keys.each do |key| | ||
Rails.cache.delete key | ||
cached_keys.delete key | ||
end | ||
end | ||
|
||
def remove_cached_key(key) | ||
cached_keys.delete key | ||
end | ||
module SuperCache | ||
module CacheMetaInfo | ||
module RedisStore | ||
def append_cached_key(key) | ||
cached_keys << key | ||
end | ||
def clear_related_caches | ||
cached_keys.each do |key| | ||
Rails.cache.delete key | ||
cached_keys.delete key | ||
end | ||
end | ||
|
||
def remove_cached_key(key) | ||
cached_keys.delete key | ||
end | ||
|
||
def self.included(base) | ||
base.class_eval do | ||
include ::Redis::Objects unless included_modules.include?(::Redis::Objects) | ||
set :cached_keys | ||
def self.included(base) | ||
base.class_eval do | ||
include ::Redis::Objects unless included_modules.include?(::Redis::Objects) | ||
set :cached_keys | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require File.expand_path('test_helper', File.dirname(__FILE__)) | ||
require File.expand_path('my_controller', File.dirname(__FILE__)) | ||
Rails.cache = ActiveSupport::Cache::MemCacheStore.new | ||
class Model | ||
include SuperCache::CacheMetaInfo | ||
include SuperCache::CacheMetaInfo::MemCacheStore | ||
attr_accessor :id | ||
def initialize(id) | ||
@id = id | ||
end | ||
end | ||
class MyController | ||
super_caches_page :index, :subject => Proc.new { @model } | ||
def index | ||
$model = @model = Model.new(10) | ||
render :text => @model.id | ||
end | ||
end | ||
class CacheMetaIntoTest < ActionController::TestCase | ||
tests MyController | ||
test "should get index" do | ||
get :index | ||
assert_response :success | ||
assert_equal '10', @response.body.strip | ||
assert_equal '10', Rails.cache.read('test.host/my', :raw => true) | ||
assert_equal $model.key_for_cached_keys, 'Model:10:cached_keys' | ||
assert_equal $model.cached_keys.size, 1 | ||
assert_equal $model.cached_keys[0], 'test.host/my' | ||
$model.clear_related_caches | ||
assert_nil Rails.cache.read('test.host/my', :raw => true) | ||
end | ||
end |