cache-store-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Honk, LLC.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ # CacheStoreApi
2
+
3
+ ## lazy_cache
4
+
5
+ Lazily cache the contents of the block. It takes the cache key and time to expiration as arguments.
6
+
7
+ CacheStoreApi.lazy_cache("cache-key", 1.week) do
8
+ @my_expensive_models = Model.all(:conditions => "some-expensive-query")
9
+ render_to_string(:template => "my/template/path/index.html")
10
+ end.tap do |html|
11
+ render :text => html
12
+ end
13
+
14
+ ## expire
15
+
16
+ Expires the given cache key.
17
+
18
+ CacheStoreApi.expire("cache-key")
19
+
20
+ ## cache
21
+
22
+ Access to the raw cache object.
23
+
24
+ CacheStoreApi.cache.instance_variable_get("@pool")
@@ -0,0 +1,39 @@
1
+ module CacheStoreApi
2
+ module CommonMethods
3
+ def lazy_cache(key, expiration=3600)
4
+ if block_given?
5
+ unless output = cache.read(key)
6
+ output = yield
7
+ cache.write(key, output, :expires_in => expiration)
8
+ end
9
+ output
10
+ else
11
+ cache.read(key)
12
+ end
13
+ end
14
+
15
+ def expire(key)
16
+ cache.delete(key)
17
+ end
18
+
19
+ def data
20
+ cache.instance_variable_get(:@data)
21
+ end
22
+ end
23
+ extend CommonMethods
24
+
25
+ extend(Module.new do
26
+ attr_reader :cache_lambda
27
+ def cache
28
+ cache_lambda.call
29
+ end
30
+
31
+ def set_cache(&block)
32
+ @cache_lambda = block
33
+ end
34
+ end)
35
+
36
+ def cache
37
+ CacheStoreApi.cache
38
+ end
39
+ end
@@ -0,0 +1,24 @@
1
+ module CacheStoreApi
2
+ class TestCache
3
+ attr_reader :data
4
+ def initialize
5
+ @data = {}
6
+ end
7
+
8
+ def write(key, value, options = nil)
9
+ data[key] = value
10
+ end
11
+
12
+ def read(key, options = nil)
13
+ data[key]
14
+ end
15
+
16
+ def delete(key, options = nil)
17
+ data.delete key
18
+ end
19
+
20
+ def exist?(key, options = nil)
21
+ data.exists? key
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module CacheStoreApi
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cache-store-api
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Brian Takita
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-21 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ version_requirements: *id001
33
+ description: Ruby cache methods built on top of Rails and Sinatra caching.
34
+ email:
35
+ - brian@honk.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - lib/cache-store-api.rb
44
+ - lib/cache-store-api/version.rb
45
+ - lib/cache-store-api/test_cache.rb
46
+ - LICENSE
47
+ - README.md
48
+ has_rdoc: true
49
+ homepage: http://github.com/honkster/cache-store-api
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 1
72
+ - 3
73
+ - 6
74
+ version: 1.3.6
75
+ requirements: []
76
+
77
+ rubyforge_project: bundler
78
+ rubygems_version: 1.3.7
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Ruby cache methods built on top of Rails and Sinatra caching.
82
+ test_files: []
83
+