cachethod 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/README.md +20 -7
- data/lib/cachethod/version.rb +1 -1
- data/lib/cachethod.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzBhZGIxMGYzMDQxMDY1ZjJmZDRlOGQyZTRjMjg2MWVhM2UxNzA2OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Yjc1Nzc1MGQ1MGNjZDE4OGUxMmE2MGI5MjIwNzQ4ODBhMTM3NmVlZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MGQ5N2JiOWM0MGU2N2VkZWFlODQ0Y2NjZGQ1Y2E0N2Y1ZjA2MmQ4NDhhMjFm
|
10
|
+
MjFjYjA5MDdlYzgyNjA3NjFiYzE3OWZmMjBkZTYxNDk2MTVlZjdiMGY5YTI4
|
11
|
+
YmE3ODFlNWZjOTdmZDk1ZTY3YThmMmM3NTBlODhhZmY3ZWNiNjM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NWFiOTZjMTYwMWRlNjk5NTAwMDk2MTM0MmIxZThiZWViM2E3Y2FlYTA5Yjc1
|
14
|
+
ZmUyYmRjOGE3ODUyN2IwNTVjYmZhNzRiZmFiMGViMjRmNjVhMzA4MmYwZDAw
|
15
|
+
YWE2MGZiMWE2MDIxMGYyNzJmYWUxOTQ4ZjdhMWJmNzJjZTdiNTQ=
|
data/README.md
CHANGED
@@ -19,7 +19,7 @@ will be reflected also on Cachethod methods.
|
|
19
19
|
In Gemfile
|
20
20
|
|
21
21
|
```ruby
|
22
|
-
gem 'cachethod'
|
22
|
+
gem 'cachethod', '~> 0.1.2'
|
23
23
|
```
|
24
24
|
|
25
25
|
Then run
|
@@ -32,6 +32,14 @@ bundle install
|
|
32
32
|
|
33
33
|
First step is including **Cachethod** module to your class.
|
34
34
|
|
35
|
+
```ruby
|
36
|
+
class User < ActiveRecord::Base
|
37
|
+
include Cachethod
|
38
|
+
|
39
|
+
...
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
35
43
|
Next you can choose one of following methods:
|
36
44
|
|
37
45
|
```ruby
|
@@ -53,7 +61,7 @@ class User < ActiveRecord::Base
|
|
53
61
|
|
54
62
|
cache_method :some_io_method, expires_in: 10.minutes
|
55
63
|
|
56
|
-
def some_io_method
|
64
|
+
def some_io_method arg1
|
57
65
|
...
|
58
66
|
end
|
59
67
|
end
|
@@ -63,11 +71,16 @@ Then invoke cached method multiple times in the usual way and you will
|
|
63
71
|
see the difference:
|
64
72
|
|
65
73
|
```ruby
|
66
|
-
user.some_io_method
|
67
|
-
user.some_io_method
|
68
|
-
user.some_io_method
|
74
|
+
user.some_io_method(2) # this will take a long time
|
75
|
+
user.some_io_method(2) # you get cached result instantly
|
76
|
+
user.some_io_method(3) # this will take a long time again
|
77
|
+
user.some_io_method(3) # you get cached result instantly
|
78
|
+
user.some_io_method(2) # you get cached result instantly
|
69
79
|
```
|
70
80
|
|
81
|
+
Note that Cachethod takes method arguments into the account and when you change
|
82
|
+
arguments it will need to cache method result also.
|
83
|
+
|
71
84
|
If you want to access uncached version of your method then you can do:
|
72
85
|
|
73
86
|
```ruby
|
@@ -98,13 +111,13 @@ into the equivalent of:
|
|
98
111
|
|
99
112
|
```ruby
|
100
113
|
class Stormtrooper < ActiveRecord::Base
|
101
|
-
def some_io_method
|
114
|
+
def some_io_method *args
|
102
115
|
Rails.cache.fetch(:some_key, expires_in: 10.minutes) do
|
103
116
|
...
|
104
117
|
end
|
105
118
|
end
|
106
119
|
|
107
|
-
def another_io_method
|
120
|
+
def another_io_method *args
|
108
121
|
Rails.cache.fetch(:another_key, expires_in: 10.minutes) do
|
109
122
|
...
|
110
123
|
end
|
data/lib/cachethod/version.rb
CHANGED
data/lib/cachethod.rb
CHANGED
@@ -31,7 +31,7 @@ module Cachethod
|
|
31
31
|
define_method "#{name}_cached" do
|
32
32
|
cache_key = "cachethod.#{self.class.to_s.underscore}."
|
33
33
|
cache_key += "#{hash}.#{name}."
|
34
|
-
cache_key += args.
|
34
|
+
cache_key += args.hash.to_s
|
35
35
|
|
36
36
|
Rails.cache.fetch(cache_key, *args) do
|
37
37
|
send("#{name}!")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cachethod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rene Klacan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|