object_cache 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +34 -0
- data/lib/object_cache/object_cache.rb +1 -1
- data/lib/object_cache/rails_store.rb +4 -0
- data/lib/object_cache/version.rb +1 -1
- metadata +8 -8
data/README.md
CHANGED
@@ -34,6 +34,40 @@ The yml file looks like this:
|
|
34
34
|
|
35
35
|
it assumes ClassName has a method find which can be used by ClassName.find([4,5]) and returns the correct objects. (usually ActiveRecord, but can be used for mongoid objects, etc.)
|
36
36
|
|
37
|
+
### Class cache
|
38
|
+
|
39
|
+
Class cache uses the ObjectCache::ClassCacher.cache("Foo", [1,2,3]) syntax to store Foo objects with ids 1,2,3 in cache (they can then be accessed in any permutation via ObjectCache::ClassCacher.cache("Foo", 1)
|
40
|
+
|
41
|
+
We recommend doing something like this to make the implementation easier:
|
42
|
+
|
43
|
+
class Foo < ActiveRecord::Base
|
44
|
+
|
45
|
+
def self.cache(ids=[])
|
46
|
+
ObjectCache::ClassCacher.cache("Foo", ids)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
and from this point simply use object_cache by:
|
52
|
+
|
53
|
+
Foo.cache(1)
|
54
|
+
Foo.cache(1,2,3)
|
55
|
+
or
|
56
|
+
Foo.cache([1,2,3])
|
57
|
+
|
58
|
+
### Cache Stores
|
59
|
+
|
60
|
+
by default, ObjectCache stores the cached objects in memory, using the ObjectCache::MemoryStore class. The current supported stores are memory store and rails store which uses Rails' abstraction of cache store to store the objects.
|
61
|
+
|
62
|
+
in the object_cache initializer define the cache store by doing this:
|
63
|
+
|
64
|
+
require "object_cache/rails_store"
|
65
|
+
ObjectCache.cache_store = ObjectCache::RailsStore
|
66
|
+
|
67
|
+
The rails cache store assumes that Rails.cache is defined, and will use whatever cache store you're using in your rails application.
|
68
|
+
|
69
|
+
This can be easily customizable, and you can write your own cache store if you like (feel free to contribute)
|
70
|
+
|
37
71
|
## Contributing
|
38
72
|
|
39
73
|
1. Fork it
|
data/lib/object_cache/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: object_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-22 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70273803229640 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70273803229640
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70273803229120 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.9.2
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70273803229120
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: timecop
|
38
|
-
requirement: &
|
38
|
+
requirement: &70273803228740 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70273803228740
|
47
47
|
description: simple object cache for ruby
|
48
48
|
email:
|
49
49
|
- tcaspy@gmail.com
|