zikaron 0.1.0 → 0.1.1
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.
- data/README.md +3 -3
- data/lib/zikaron/remembers/actions.rb +22 -18
- data/lib/zikaron/version.rb +1 -1
- data/lib/zikaron.rb +6 -1
- data/zikaron.gemspec +1 -0
- metadata +19 -3
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Zikaron
|
2
2
|
|
3
|
-
|
3
|
+
Dead simple short-term memory, AKA caching, for Rails applications. Originally designed to cache API responses for performance.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,7 +20,7 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
Create config/zikaron.rb:
|
22
22
|
|
23
|
-
Zikaron.
|
23
|
+
Zikaron.configure do |config|
|
24
24
|
config.redis_url = "http://foo.bar.bat.baz.com/"
|
25
25
|
config.memory_duration = 50 #seconds
|
26
26
|
config.cache_name = :my_application_name
|
@@ -39,7 +39,7 @@ Then, in your controller:
|
|
39
39
|
end
|
40
40
|
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
## Contributing
|
44
44
|
|
45
45
|
1. Fork it
|
@@ -1,28 +1,32 @@
|
|
1
|
-
module
|
1
|
+
module Zikaron
|
2
2
|
|
3
|
-
module
|
3
|
+
module Remembers
|
4
4
|
|
5
|
-
|
6
|
-
base.extend ClassMethods
|
7
|
-
end
|
5
|
+
module Actions
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
actions = [actions].flatten
|
12
|
-
send(:around_filter, :cache, :only => actions)
|
7
|
+
def self.included(base)
|
8
|
+
base.extend ClassMethods
|
13
9
|
end
|
14
|
-
end
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
module ClassMethods
|
12
|
+
def remembers(actions=[])
|
13
|
+
actions = [actions].flatten
|
14
|
+
send(:around_filter, :cache, :only => actions)
|
15
|
+
end
|
20
16
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
|
18
|
+
def cache
|
19
|
+
yield and return unless Zikaron.redis
|
20
|
+
if cached = Zikaron.redis.get(request.url)
|
21
|
+
respond_with cached and return
|
22
|
+
end
|
23
|
+
yield
|
24
|
+
Zikaron.redis.set request.url, response.body
|
25
|
+
Zikaron.redis.expireat request.url, (Time.now + Zikaron.config.memory_duration).to_i
|
26
|
+
end
|
27
|
+
|
24
28
|
end
|
25
29
|
|
26
30
|
end
|
27
31
|
|
28
|
-
end
|
32
|
+
end
|
data/lib/zikaron/version.rb
CHANGED
data/lib/zikaron.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "redis-namespace"
|
1
2
|
require "zikaron/version"
|
2
3
|
require "zikaron/remembers/actions"
|
3
4
|
|
@@ -7,6 +8,10 @@ module Zikaron
|
|
7
8
|
attr_accessor :config
|
8
9
|
end
|
9
10
|
|
11
|
+
def self.redis
|
12
|
+
@redis ||= Redis::Namespace.new(config.cache_name, :redis => Redis.connect(:url => config.redis_url))
|
13
|
+
end
|
14
|
+
|
10
15
|
def self.configure(&block)
|
11
16
|
@config = Configuration.new
|
12
17
|
yield(config)
|
@@ -20,7 +25,7 @@ module Zikaron
|
|
20
25
|
attr_accessor :redis_url, :memory_duration, :cache_name
|
21
26
|
|
22
27
|
def initialize
|
23
|
-
self.redis_url ||= '
|
28
|
+
self.redis_url ||= 'redis://localhost:6379/'
|
24
29
|
self.memory_duration ||= 60
|
25
30
|
self.cache_name ||= 'zikaron'
|
26
31
|
end
|
data/zikaron.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zikaron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -28,6 +28,22 @@ dependencies:
|
|
28
28
|
- - ! '>='
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: redis-namespace
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
31
47
|
- !ruby/object:Gem::Dependency
|
32
48
|
name: bundler
|
33
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
108
|
version: '0'
|
93
109
|
segments:
|
94
110
|
- 0
|
95
|
-
hash:
|
111
|
+
hash: -3638186221202926964
|
96
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
113
|
none: false
|
98
114
|
requirements:
|
@@ -101,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
117
|
version: '0'
|
102
118
|
segments:
|
103
119
|
- 0
|
104
|
-
hash:
|
120
|
+
hash: -3638186221202926964
|
105
121
|
requirements: []
|
106
122
|
rubyforge_project:
|
107
123
|
rubygems_version: 1.8.24
|