cached_resource 1.0.0 → 1.0.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 → README.md} +5 -1
- data/cached_resource.gemspec +0 -1
- data/lib/cached_resource/caching.rb +2 -17
- data/lib/cached_resource/config.rb +3 -0
- data/lib/cached_resource/version.rb +1 -1
- data/lib/cached_resource.rb +0 -2
- metadata +14 -28
data/{README → README.md}
RENAMED
|
@@ -5,7 +5,7 @@ CachedResource helps ActiveResource by caching responses according to request pa
|
|
|
5
5
|
gem install cached_resource
|
|
6
6
|
|
|
7
7
|
## Configuration
|
|
8
|
-
CachedResource works "out of the box" with ActiveResource. By default, it caches responses to an `ActiveSupport::Cache::MemoryStore` and logs to an `ActiveSupport::BufferedLogger` attached to a `StringIO` object.
|
|
8
|
+
CachedResource works "out of the box" with ActiveResource. By default, it caches responses to an `ActiveSupport::Cache::MemoryStore` and logs to an `ActiveSupport::BufferedLogger` attached to a `StringIO` object. **In a Rails 3 environment**, CachedResource will attach itself to the Rails logger and cache.
|
|
9
9
|
|
|
10
10
|
Turn CachedResource off. This will cause all ActiveResource responses to be retrieved normally (i.e. via the network).
|
|
11
11
|
|
|
@@ -34,3 +34,7 @@ Sit back and relax! If you need to reload a particular request you can do someth
|
|
|
34
34
|
|
|
35
35
|
## Testing
|
|
36
36
|
rake
|
|
37
|
+
|
|
38
|
+
## Credit/Inspiration
|
|
39
|
+
quamen and [this gist](http://gist.github.com/947734)
|
|
40
|
+
latimes and [this plugin](http://github.com/latimes/cached_resource)
|
data/cached_resource.gemspec
CHANGED
|
@@ -34,7 +34,7 @@ module CachedResource
|
|
|
34
34
|
# no cache entry exists, send a new request.
|
|
35
35
|
def find_via_cache(key, *arguments)
|
|
36
36
|
result = CachedResource.cache.read(key).try(:dup)
|
|
37
|
-
result &&
|
|
37
|
+
result && CachedResource.logger.info("#{CachedResource::Config::LOGGER_PREFIX} READ #{key} for #{arguments.inspect}")
|
|
38
38
|
result || find_via_reload(key, *arguments)
|
|
39
39
|
end
|
|
40
40
|
|
|
@@ -43,7 +43,7 @@ module CachedResource
|
|
|
43
43
|
def find_via_reload(key, *arguments)
|
|
44
44
|
result = find_without_cache(*arguments)
|
|
45
45
|
CachedResource.cache.write(key, result, :expires_in => CachedResource.config.cache_time_to_live)
|
|
46
|
-
|
|
46
|
+
CachedResource.logger.info("#{CachedResource::Config::LOGGER_PREFIX} WRITE #{key} for #{arguments.inspect}")
|
|
47
47
|
result
|
|
48
48
|
end
|
|
49
49
|
|
|
@@ -52,21 +52,6 @@ module CachedResource
|
|
|
52
52
|
"#{name.parameterize.gsub("-", "/")}/#{arguments.join('/')}".downcase
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
# log a message indicating a cached resource event
|
|
56
|
-
def log(type, msg)
|
|
57
|
-
c = Term::ANSIColor
|
|
58
|
-
type_string = "Cached Resource #{type.to_s.upcase}"
|
|
59
|
-
|
|
60
|
-
case type
|
|
61
|
-
when :read
|
|
62
|
-
type_string = c.intense_black + c.bold + type_string + c.clear
|
|
63
|
-
when :write
|
|
64
|
-
type_string = c.yellow + c.bold + type_string + c.clear
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
CachedResource.logger.info "#{type_string} #{msg}"
|
|
68
|
-
end
|
|
69
|
-
|
|
70
55
|
end
|
|
71
56
|
end
|
|
72
57
|
end
|
|
@@ -7,6 +7,9 @@ module CachedResource
|
|
|
7
7
|
# set default cache time to live to 1 week
|
|
8
8
|
DEFAULT_CACHE_TIME_TO_LIVE = 604800
|
|
9
9
|
|
|
10
|
+
# prefix for log messages
|
|
11
|
+
LOGGER_PREFIX = "[cached_resource]"
|
|
12
|
+
|
|
10
13
|
attr_accessor :cache_enabled, :cache_time_to_live, :logger, :cache
|
|
11
14
|
|
|
12
15
|
# initialize the config with caching enabled and
|
data/lib/cached_resource.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cached_resource
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 21
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 1
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
10
|
-
version: 1.0.
|
|
9
|
+
- 1
|
|
10
|
+
version: 1.0.1
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Andrew Chan
|
|
@@ -15,10 +15,11 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2011-10-
|
|
18
|
+
date: 2011-10-21 00:00:00 Z
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
21
|
-
|
|
21
|
+
name: activeresource
|
|
22
|
+
prerelease: false
|
|
22
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
23
24
|
none: false
|
|
24
25
|
requirements:
|
|
@@ -28,11 +29,11 @@ dependencies:
|
|
|
28
29
|
segments:
|
|
29
30
|
- 0
|
|
30
31
|
version: "0"
|
|
31
|
-
|
|
32
|
-
name: activeresource
|
|
32
|
+
type: :runtime
|
|
33
33
|
version_requirements: *id001
|
|
34
34
|
- !ruby/object:Gem::Dependency
|
|
35
|
-
|
|
35
|
+
name: activesupport
|
|
36
|
+
prerelease: false
|
|
36
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
|
37
38
|
none: false
|
|
38
39
|
requirements:
|
|
@@ -42,11 +43,11 @@ dependencies:
|
|
|
42
43
|
segments:
|
|
43
44
|
- 0
|
|
44
45
|
version: "0"
|
|
45
|
-
|
|
46
|
-
name: activesupport
|
|
46
|
+
type: :runtime
|
|
47
47
|
version_requirements: *id002
|
|
48
48
|
- !ruby/object:Gem::Dependency
|
|
49
|
-
|
|
49
|
+
name: rspec
|
|
50
|
+
prerelease: false
|
|
50
51
|
requirement: &id003 !ruby/object:Gem::Requirement
|
|
51
52
|
none: false
|
|
52
53
|
requirements:
|
|
@@ -56,23 +57,8 @@ dependencies:
|
|
|
56
57
|
segments:
|
|
57
58
|
- 0
|
|
58
59
|
version: "0"
|
|
59
|
-
prerelease: false
|
|
60
|
-
name: term-ansicolor
|
|
61
|
-
version_requirements: *id003
|
|
62
|
-
- !ruby/object:Gem::Dependency
|
|
63
60
|
type: :development
|
|
64
|
-
|
|
65
|
-
none: false
|
|
66
|
-
requirements:
|
|
67
|
-
- - ">="
|
|
68
|
-
- !ruby/object:Gem::Version
|
|
69
|
-
hash: 3
|
|
70
|
-
segments:
|
|
71
|
-
- 0
|
|
72
|
-
version: "0"
|
|
73
|
-
prerelease: false
|
|
74
|
-
name: rspec
|
|
75
|
-
version_requirements: *id004
|
|
61
|
+
version_requirements: *id003
|
|
76
62
|
description: Enables request-based caching for ActiveResource
|
|
77
63
|
email: email@suspi.net
|
|
78
64
|
executables: []
|
|
@@ -86,7 +72,7 @@ files:
|
|
|
86
72
|
- .rspec
|
|
87
73
|
- Gemfile
|
|
88
74
|
- MIT-LICENSE
|
|
89
|
-
- README
|
|
75
|
+
- README.md
|
|
90
76
|
- Rakefile
|
|
91
77
|
- cached_resource.gemspec
|
|
92
78
|
- lib/cached_resource.rb
|