find_cache 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +4 -2
- data/README.rdoc +31 -26
- data/lib/find_cache/version.rb +1 -1
- metadata +13 -13
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
Copyright 2012
|
1
|
+
Copyright (c) 2012 Mustafa TURAN
|
2
|
+
|
3
|
+
MIT License
|
2
4
|
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
6
|
a copy of this software and associated documentation files (the
|
@@ -17,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -23,15 +23,21 @@ Or install it yourself as:
|
|
23
23
|
### Sample Models:
|
24
24
|
|
25
25
|
User (`has_one :user_detail`) ->
|
26
|
-
|
27
|
-
|
26
|
+
|
27
|
+
find_cache_has_one :user_detail, UserDetail, :user_id
|
28
|
+
|
29
|
+
find_cache_has_one attr_name_or_any_other_name, ModelName, foreign_key
|
30
|
+
|
31
|
+
- name
|
28
32
|
- email
|
29
33
|
- username
|
30
|
-
- password
|
31
34
|
|
32
35
|
UserDetail (`belongs_to :user`) ->
|
33
|
-
|
34
|
-
|
36
|
+
|
37
|
+
find_cache_belongs_to :user, User, :user_id
|
38
|
+
|
39
|
+
find_cache_belongs_to attr_name_or_any_other_name, ModelName, foreign_key
|
40
|
+
|
35
41
|
- user_id
|
36
42
|
- avatar
|
37
43
|
- age
|
@@ -42,34 +48,33 @@ UserDetail (`belongs_to :user`) ->
|
|
42
48
|
|
43
49
|
### Create a ruby file under config/initializers and add the following codes:
|
44
50
|
|
45
|
-
|
46
|
-
module
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
+
module ActiveRecord
|
52
|
+
module CounterCache
|
53
|
+
def increment_counter(counter_name, id)
|
54
|
+
expire_find_cache(name, id)
|
55
|
+
update_counters(id, counter_name => 1)
|
56
|
+
end
|
57
|
+
|
58
|
+
def decrement_counter(counter_name, id)
|
59
|
+
expire_find_cache(name, id)
|
60
|
+
update_counters(id, counter_name => -1)
|
61
|
+
end
|
62
|
+
|
63
|
+
def expire_find_cache(name, id)
|
64
|
+
key = FindCache::KeyGen.cache_key(name, id)
|
65
|
+
Rails.cache.delete(key)
|
66
|
+
$find_cache_store[FindCache::KeyGen.global_cache_key].delete(key)
|
67
|
+
end
|
68
|
+
end
|
51
69
|
end
|
52
70
|
|
53
|
-
def decrement_counter(counter_name, id)
|
54
|
-
expire_find_cache(name, id)
|
55
|
-
update_counters(id, counter_name => -1)
|
56
|
-
end
|
57
|
-
|
58
|
-
def expire_find_cache(name, id)
|
59
|
-
key = FindCache::KeyGen.cache_key(name, id)
|
60
|
-
Rails.cache.delete(key)
|
61
|
-
$find_cache_store[FindCache::KeyGen.global_cache_key].delete(key)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
`
|
66
|
-
|
67
71
|
## Notes
|
68
72
|
|
69
73
|
Tested with dalli (https://github.com/mperham/dalli).
|
70
74
|
|
71
75
|
## Credits
|
72
|
-
|
76
|
+
|
77
|
+
FindCache is part of http://videofork.com project.
|
73
78
|
|
74
79
|
## Contributing
|
75
80
|
|
data/lib/find_cache/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: find_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -32,26 +32,26 @@ dependencies:
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: 0.2.0
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: 0.2.0
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: sqlite3
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
51
|
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
|
-
type: :
|
54
|
+
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
@@ -60,21 +60,21 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: dalli
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
69
|
+
version: 2.1.0
|
70
70
|
type: :development
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
|
-
- -
|
75
|
+
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
77
|
+
version: 2.1.0
|
78
78
|
description: ! 'Makes ActiveRecord ''find_by_id, find_by_(attr)'' methods and ''has_one,
|
79
79
|
belongs_to relations'' cacheable by id or any referenced columns using Rails.cache
|
80
80
|
methods. It also supports fetching multiple records using ids with find_all_cache
|
@@ -167,7 +167,7 @@ files:
|
|
167
167
|
- test/dummy/tmp/cache/58D/B70/Post%2Fuser_id-1
|
168
168
|
- test/find_cache_test.rb
|
169
169
|
- test/test_helper.rb
|
170
|
-
homepage: https://github.com/mustafaturan/
|
170
|
+
homepage: https://github.com/mustafaturan/find_cache
|
171
171
|
licenses: []
|
172
172
|
post_install_message:
|
173
173
|
rdoc_options: []
|