cache_tree 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +137 -11
- data/VERSION +1 -1
- data/cache_tree.gemspec +2 -2
- data/lib/cache_tree.rb +1 -1
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -17,24 +17,150 @@ in some sort of background job solution.
|
|
17
17
|
|
18
18
|
Trees are cool :)
|
19
19
|
|
20
|
-
==
|
20
|
+
== Simple example.
|
21
21
|
|
22
22
|
require 'rubygems'
|
23
23
|
require 'cache_tree'
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
# Setup
|
26
|
+
CacheTree::Node.directory = 'cache/tree'
|
27
|
+
|
28
|
+
# Create a cache node in the tree
|
29
|
+
node = CacheTree.node({:name => 'node', :value => 1})
|
30
|
+
|
31
|
+
# Store data into cache!
|
32
|
+
puts CacheTree.use(node) { 'This is my complex operation!' }
|
33
|
+
|
34
|
+
# Pull data from the cache, if exists in cache and all that is
|
35
|
+
# handled internally!
|
36
|
+
puts CacheTree.use(node) { 'Even if this changes cached data will be returned' }
|
37
|
+
|
38
|
+
# Expiring!
|
39
|
+
node.expire
|
40
|
+
|
41
|
+
# Removing expired files!
|
42
|
+
node.clean
|
43
|
+
|
44
|
+
== Connecting nodes example.
|
45
|
+
|
46
|
+
require 'rubygems'
|
47
|
+
require 'cache_tree'
|
48
|
+
|
49
|
+
# Setup
|
50
|
+
CacheTree::Node.directory = 'cache/tree'
|
51
|
+
|
52
|
+
# Create/Handle two separated cache trees.
|
53
|
+
parent_1 = CacheTree.node({:name => 'parent_1', :value => 1})
|
54
|
+
parent_2 = CacheTree.node({:name => 'parent_2', :value => 2})
|
55
|
+
|
56
|
+
# Each tree has sub-nodes.
|
57
|
+
child_1 = CacheTree.node({:name => 'child_1', :value => 1})
|
58
|
+
child_2 = CacheTree.node({:name => 'child_2', :value => 2})
|
59
|
+
child_3 = CacheTree.node({:name => 'child_3', :value => 3})
|
60
|
+
|
61
|
+
# Create a cache tree relationship between the nodes.
|
62
|
+
parent_1.add_child(child_1)
|
63
|
+
parent_2.add_child(child_2)
|
64
|
+
parent_1.add_child(child_3)
|
65
|
+
|
66
|
+
puts CacheTree.use(child_1) { 'This is child 1 cache' }
|
67
|
+
puts CacheTree.use(child_2) { 'This is child 2 cache' }
|
68
|
+
puts CacheTree.use(child_3) { 'This is child 3 cache' }
|
69
|
+
|
70
|
+
# Expire cache for all nodes below parent 1.
|
71
|
+
parent_1.expire
|
72
|
+
|
73
|
+
# parent 2 cache is still active at this point, parent 1 cache needs to be regenerated.
|
74
|
+
|
75
|
+
# remove expired files from child nodes (1, 3)
|
76
|
+
child_1.clean
|
77
|
+
child_3.clean
|
78
|
+
|
79
|
+
== Example Output
|
80
|
+
|
81
|
+
bash-3.2$ ruby cache_tree.usage_example.rb
|
82
|
+
This is child 1 cache
|
83
|
+
This is child 2 cache
|
84
|
+
This is child 3 cache
|
85
|
+
bash-3.2$ tree cache
|
86
|
+
cache
|
87
|
+
`-- tree
|
88
|
+
|-- parent_1
|
89
|
+
| `-- 1
|
90
|
+
| |-- btree.key
|
91
|
+
| |-- child_1
|
92
|
+
| | `-- 1
|
93
|
+
| | `-- btree.key
|
94
|
+
| `-- child_3
|
95
|
+
| `-- 3
|
96
|
+
| `-- btree.key
|
97
|
+
`-- parent_2
|
98
|
+
`-- 2
|
99
|
+
|-- btree.key
|
100
|
+
`-- child_2
|
101
|
+
`-- 2
|
102
|
+
|-- btree.key
|
103
|
+
`-- c1533963ef2c86a1f8c80cde871d0b09.cache
|
104
|
+
|
105
|
+
11 directories, 6 files
|
106
|
+
bash-3.2$ cat cache/tree/parent_2/2/child_2/2/c1533963ef2c86a1f8c80cde871d0b09.cache
|
107
|
+
This is child 2 cache
|
108
|
+
|
109
|
+
== Complex example.
|
110
|
+
|
111
|
+
require 'rubygems'
|
112
|
+
require 'cache_tree'
|
113
|
+
|
114
|
+
# Mocks
|
115
|
+
class ActiveRecordMock
|
116
|
+
attr_accessor :id
|
117
|
+
def initialize
|
118
|
+
@id = 1
|
28
119
|
end
|
29
120
|
end
|
30
121
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
122
|
+
class User < ActiveRecordMock; end
|
123
|
+
class Post < ActiveRecordMock; end
|
124
|
+
class Comment < ActiveRecordMock; end
|
125
|
+
class Like < ActiveRecordMock; end
|
126
|
+
|
127
|
+
# Easily Setup complex cached trees.
|
128
|
+
user = CacheTree.node(User.new)
|
129
|
+
post = CacheTree.node(Post.new)
|
130
|
+
comment = CacheTree.node(Comment.new)
|
131
|
+
like = CacheTree.node(Like.new)
|
132
|
+
|
133
|
+
user.add_child(post)
|
134
|
+
post.add_child(comment)
|
135
|
+
comment.add_child(like)
|
136
|
+
|
137
|
+
# Setup
|
138
|
+
CacheTree::Node.directory = 'cache/tree'
|
139
|
+
|
140
|
+
# Example Usage.
|
141
|
+
# - first time block gets executed
|
142
|
+
# - second time will be pulled out from cache!
|
143
|
+
# - you can grab any of the nodes and expire all the cache below that
|
144
|
+
# node
|
145
|
+
puts CacheTree.use(like) { 'Generating cache' }
|
146
|
+
|
147
|
+
# Expire all cache below post with id 1 but leave user cache alone.
|
148
|
+
post.expire
|
149
|
+
|
150
|
+
puts CacheTree.use(like) { 'Generating new cache' }
|
151
|
+
puts CacheTree.use(like) { 'xxxxxxxxxxxxxxxxxxxx' } # => will output 'Generating new cache'
|
152
|
+
|
153
|
+
# you can debug any node to figure out what is going on with the cache
|
154
|
+
# at that particular point.
|
155
|
+
# - when debugging, the actual cache file will be shown in green
|
156
|
+
# (active cache)
|
157
|
+
# - all dead cache will be shown in red
|
158
|
+
# - if cache file has not been generated it would be printed in yellow!
|
159
|
+
like.debug
|
160
|
+
|
161
|
+
# Use this to remove expired cache files.
|
162
|
+
like.clean
|
163
|
+
|
38
164
|
|
39
165
|
== Copyright
|
40
166
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/cache_tree.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cache_tree}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["kazuyoshi tlacaelel"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2013-04-22}
|
13
13
|
s.description = %q{Cache based on btrees, for large ammounts of cache.}
|
14
14
|
s.email = %q{kazu.dev@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/cache_tree.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cache_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- kazuyoshi tlacaelel
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2013-04-22 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|