restrict_cache 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/lib/restrict_cache/accessible.rb +11 -1
- data/lib/restrict_cache/action_controller_ext.rb +1 -1
- data/lib/restrict_cache/active_record_ext.rb +20 -9
- data/lib/restrict_cache/cacheable.rb +5 -3
- data/lib/restrict_cache/railtie.rb +2 -1
- data/lib/restrict_cache/version.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c29fdf424ebafc1734aacbc3da69ca1a5ff9563
|
4
|
+
data.tar.gz: 48cc0cd115be5e997c74763b02569a7c8a978b17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c29896eacf36a4e75f08752e1119ac5f65599894191ce44ee005790782d2164dd28a186df8fd37dc7e729ff4548c2350a1c208a2eca39642ce43ce8381bb9d93
|
7
|
+
data.tar.gz: 680747417162f543812e2ce6c34bca13b13d5847f6fe8e746cbd0b26c1329f3ba1cbba12e806c701964aa3f1796457e914e7685e99ff446ed27ea33d75781581
|
data/README.md
CHANGED
@@ -34,6 +34,15 @@ end
|
|
34
34
|
|
35
35
|
#### Callbacks (Around Action)
|
36
36
|
|
37
|
+
```ruby
|
38
|
+
class MyController < ApplicationController
|
39
|
+
# cache_sweep_action :index, :show
|
40
|
+
cache_sweep_action
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
#### ActiveRecord Cache
|
45
|
+
|
37
46
|
```ruby
|
38
47
|
class MyModel < ActiveRecord::Base; end
|
39
48
|
MyModel.find_with_restrict_cache(id_or_ids)
|
@@ -2,13 +2,23 @@ module RestrictCache
|
|
2
2
|
module Accessible
|
3
3
|
THREAD_KEY = :restrict_cache
|
4
4
|
|
5
|
-
def
|
5
|
+
def cache
|
6
6
|
Thread.current[THREAD_KEY] ||= Cacheable.new
|
7
7
|
end
|
8
8
|
|
9
9
|
def clear
|
10
10
|
Thread.current[THREAD_KEY] = nil
|
11
11
|
end
|
12
|
+
|
13
|
+
def method_missing(name, *args, &block)
|
14
|
+
super unless cache.respond_to?(name)
|
15
|
+
|
16
|
+
define_singleton_method(name) do |*a, &b|
|
17
|
+
cache.public_send(name, *a, &b)
|
18
|
+
end
|
19
|
+
|
20
|
+
send(name, *args, &block)
|
21
|
+
end
|
12
22
|
end
|
13
23
|
|
14
24
|
extend Accessible
|
@@ -1,10 +1,20 @@
|
|
1
1
|
module RestrictCache
|
2
2
|
module ActiveRecordExt
|
3
|
-
|
4
|
-
|
3
|
+
module Base
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
delegate :find_with_restrict_cache, to: :all
|
8
|
+
end
|
9
|
+
|
10
|
+
def restrict_cache
|
11
|
+
RestrictCache.add(self)
|
12
|
+
end
|
5
13
|
end
|
6
14
|
|
7
|
-
module
|
15
|
+
module Relation
|
16
|
+
AR_CACHE_KEY = Cacheable::CacheKey::ACTIVERECORD
|
17
|
+
|
8
18
|
def find_and_restrict_cache(arg)
|
9
19
|
records = find(arg)
|
10
20
|
Array(records).each(&:restrict_cache)
|
@@ -12,7 +22,7 @@ module RestrictCache
|
|
12
22
|
end
|
13
23
|
|
14
24
|
def find_from_restrict_cache(arg)
|
15
|
-
contents = RestrictCache.
|
25
|
+
contents = RestrictCache.send(AR_CACHE_KEY).contents(self.table_name)
|
16
26
|
return nil unless contents
|
17
27
|
|
18
28
|
case arg
|
@@ -36,18 +46,19 @@ module RestrictCache
|
|
36
46
|
end
|
37
47
|
end
|
38
48
|
|
49
|
+
def with_restrict_cache
|
50
|
+
self.each(&:restrict_cache)
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
39
54
|
private
|
40
55
|
def restrict_cached?(args)
|
41
|
-
content = RestrictCache.
|
56
|
+
content = RestrictCache.send(AR_CACHE_KEY).contents(self.table_name)
|
42
57
|
return false unless content
|
43
58
|
ids = content.keys
|
44
59
|
args.all? {|index| ids.include?(index) }
|
45
60
|
end
|
46
61
|
end
|
47
|
-
|
48
|
-
def restrict_cache
|
49
|
-
RestrictCache.collection.add(self)
|
50
|
-
end
|
51
62
|
end
|
52
63
|
end
|
53
64
|
|
@@ -10,10 +10,12 @@ module RestrictCache
|
|
10
10
|
ALL = [ACTIVERECORD, CUSTOM]
|
11
11
|
|
12
12
|
def self.get(content)
|
13
|
-
|
14
|
-
|
13
|
+
case
|
14
|
+
when defined?(ActiveRecord) && content.class < ActiveRecord::Base
|
15
|
+
ACTIVERECORD
|
16
|
+
else
|
17
|
+
CUSTOM
|
15
18
|
end
|
16
|
-
CUSTOM
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
@@ -9,7 +9,8 @@ module RestrictCache
|
|
9
9
|
end
|
10
10
|
|
11
11
|
ActiveSupport.on_load(:active_record) do
|
12
|
-
::ActiveRecord::Base.send(:include, RestrictCache::ActiveRecordExt)
|
12
|
+
::ActiveRecord::Base.send(:include, RestrictCache::ActiveRecordExt::Base)
|
13
|
+
::ActiveRecord::Relation.send(:include, RestrictCache::ActiveRecordExt::Relation)
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restrict_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- i2bskn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|