tmp_cache 0.0.1 → 0.0.2
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/History.txt +4 -0
- data/Manifest.txt +0 -1
- data/README.rdoc +9 -2
- data/lib/tmp_cache.rb +1 -1
- data/samples/sample.rb +3 -3
- metadata +3 -4
- data/lib/tmp_cache/cache.rb +0 -20
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/README.rdoc
CHANGED
@@ -11,13 +11,20 @@ on memory cache.
|
|
11
11
|
#!/usr/bin/env ruby
|
12
12
|
require 'tmp_cache'
|
13
13
|
|
14
|
-
TmpCache.set('name', 'shokai',
|
14
|
+
TmpCache.set('name', 'shokai', 60) # expire 60 sec
|
15
15
|
|
16
16
|
puts TmpCache.get('name') # => 'shokai'
|
17
|
-
sleep
|
17
|
+
sleep 61
|
18
18
|
puts TmpCache.get('name') # => nil
|
19
19
|
|
20
20
|
|
21
|
+
TmpCache.set('name', 'shokai')
|
22
|
+
TmpCache.set('mail', 'hashimoto@shokai.org')
|
23
|
+
TmpCache.each do |k,v|
|
24
|
+
puts "#{k} => #{v}"
|
25
|
+
end
|
26
|
+
|
27
|
+
|
21
28
|
== REQUIREMENTS:
|
22
29
|
|
23
30
|
* Ruby 1.8.7+
|
data/lib/tmp_cache.rb
CHANGED
data/samples/sample.rb
CHANGED
@@ -5,10 +5,10 @@ require 'rubygems'
|
|
5
5
|
|
6
6
|
require 'tmp_cache'
|
7
7
|
|
8
|
-
TmpCache.set('name', 'shokai', 2)
|
9
|
-
puts TmpCache.get('name')
|
8
|
+
TmpCache.set('name', 'shokai', 2) # expire 2 sec
|
9
|
+
puts TmpCache.get('name') # => 'shokai'
|
10
10
|
sleep 3
|
11
|
-
puts TmpCache.get('name')
|
11
|
+
puts TmpCache.get('name') # => nil
|
12
12
|
|
13
13
|
|
14
14
|
TmpCache.set('name', 'shokai')
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tmp_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sho Hashimoto
|
@@ -80,7 +80,6 @@ files:
|
|
80
80
|
- README.rdoc
|
81
81
|
- Rakefile
|
82
82
|
- lib/tmp_cache.rb
|
83
|
-
- lib/tmp_cache/cache.rb
|
84
83
|
- script/console
|
85
84
|
- script/destroy
|
86
85
|
- script/generate
|
data/lib/tmp_cache/cache.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
|
2
|
-
module TmpCache
|
3
|
-
class Cache
|
4
|
-
def self.cache
|
5
|
-
@@cache ||= Hash.new{|h,k| h = {:expire => 0, :value => nil}}
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.set(key, value, expire=60)
|
9
|
-
cache[key] = {:value => value, :expire => Time.now.to_i+expire}
|
10
|
-
return value
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.get(key)
|
14
|
-
if cache[key][:expire] < Time.now.to_i
|
15
|
-
return cache[key][:value] = nil
|
16
|
-
else
|
17
|
-
return cache[key][:value]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|