tmp_cache 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ === 0.0.1 2012-05-05
2
+
3
+ * start
data/Manifest.txt ADDED
@@ -0,0 +1,12 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ lib/tmp_cache.rb
6
+ lib/tmp_cache/cache.rb
7
+ script/console
8
+ script/destroy
9
+ script/generate
10
+ test/test_helper.rb
11
+ test/test_tmp_cache.rb
12
+ samples/sample.rb
data/README.rdoc ADDED
@@ -0,0 +1,55 @@
1
+ = tmp_cache
2
+
3
+ * http://github.com/shokai/tmp_cache
4
+
5
+ == DESCRIPTION:
6
+
7
+ on memory cache.
8
+
9
+ == SYNOPSIS:
10
+
11
+ #!/usr/bin/env ruby
12
+ require 'tmp_cache'
13
+
14
+ TmpCache.set('name', 'shokai', 2) # expire 2 sec
15
+
16
+ puts TmpCache.get('name') # => 'shokai'
17
+ sleep 3
18
+ puts TmpCache.get('name') # => nil
19
+
20
+
21
+ == REQUIREMENTS:
22
+
23
+ * Ruby 1.8.7+
24
+ * Ruby 1.9.3+
25
+
26
+
27
+ == INSTALL:
28
+
29
+ * gem install tmp_cache
30
+
31
+
32
+ == LICENSE:
33
+
34
+ (The MIT License)
35
+
36
+ Copyright (c) 2012 Sho Hashimoto
37
+
38
+ Permission is hereby granted, free of charge, to any person obtaining
39
+ a copy of this software and associated documentation files (the
40
+ 'Software'), to deal in the Software without restriction, including
41
+ without limitation the rights to use, copy, modify, merge, publish,
42
+ distribute, sublicense, and/or sell copies of the Software, and to
43
+ permit persons to whom the Software is furnished to do so, subject to
44
+ the following conditions:
45
+
46
+ The above copyright notice and this permission notice shall be
47
+ included in all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
50
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
52
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
53
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
54
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
55
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/tmp_cache'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'tmp_cache' do
14
+ self.developer 'Sho Hashimoto', 'hashimoto@shokai.org'
15
+ self.rubyforge_name = self.name # TODO this is default value
16
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
17
+
18
+ end
19
+
20
+ require 'newgem/tasks'
21
+ Dir['tasks/**/*.rake'].each { |t| load t }
22
+
23
+ # TODO - want other tests/tasks run by default? Add them to the list
24
+ # remove_task :default
25
+ # task :default => [:spec, :features]
@@ -0,0 +1,20 @@
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
data/lib/tmp_cache.rb ADDED
@@ -0,0 +1,39 @@
1
+
2
+ module TmpCache
3
+ VERSION = '0.0.1'
4
+
5
+ def self.cache
6
+ @@cache ||= Hash.new{|h,k| h = {:expire => 0, :value => nil}}
7
+ end
8
+
9
+ def self.set(key, value, expire=60)
10
+ cache[key] = {:value => value, :expire => Time.now.to_i+expire}
11
+ return value
12
+ end
13
+
14
+ def self.get(key)
15
+ if cache[key][:expire] < Time.now.to_i
16
+ return cache[key][:value] = nil
17
+ else
18
+ return cache[key][:value]
19
+ end
20
+ end
21
+
22
+ def self.reset
23
+ @@cache = nil
24
+ end
25
+
26
+ def self.keys
27
+ cache.keys
28
+ end
29
+
30
+ def self.values
31
+ cache.values.map{|v| v[:value] }
32
+ end
33
+
34
+ def self.each(&block)
35
+ cache.each do |k,v|
36
+ yield k, v[:value]
37
+ end
38
+ end
39
+ end
data/samples/sample.rb ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+
4
+ ## $:.push File.dirname(__FILE__)+'/../lib'
5
+
6
+ require 'tmp_cache'
7
+
8
+ TmpCache.set('name', 'shokai', 2)
9
+ puts TmpCache.get('name')
10
+ sleep 3
11
+ puts TmpCache.get('name')
12
+
13
+
14
+ TmpCache.set('name', 'shokai')
15
+ TmpCache.set('mail', 'hashimoto@shokai.org')
16
+ TmpCache.each do |k,v|
17
+ puts "#{k} => #{v}"
18
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/tmp_cache.rb'}"
9
+ puts "Loading tmp_cache gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/tmp_cache'
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestTmpCache < Test::Unit::TestCase
4
+
5
+ def setup
6
+ TmpCache.set('name', 'shokai', 2)
7
+ end
8
+
9
+ def test_get
10
+ assert TmpCache.get('name') == 'shokai'
11
+ end
12
+
13
+ def test_expire
14
+ sleep 3
15
+ assert TmpCache.get('name') == nil
16
+ end
17
+
18
+ def test_reset
19
+ TmpCache.reset
20
+ assert TmpCache.get('name') == nil
21
+ end
22
+
23
+ def test_keys
24
+ TmpCache.set('mail', 'hashimoto@shokai.org')
25
+ assert TmpCache.keys.sort == ['name', 'mail'].sort
26
+ end
27
+
28
+ def test_values
29
+ assert TmpCache.values == ['shokai']
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tmp_cache
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Sho Hashimoto
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-05-05 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rdoc
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 19
29
+ segments:
30
+ - 3
31
+ - 10
32
+ version: "3.10"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: newgem
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 5
44
+ segments:
45
+ - 1
46
+ - 5
47
+ - 3
48
+ version: 1.5.3
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: hoe
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 29
60
+ segments:
61
+ - 2
62
+ - 15
63
+ version: "2.15"
64
+ type: :development
65
+ version_requirements: *id003
66
+ description: on memory cache.
67
+ email:
68
+ - hashimoto@shokai.org
69
+ executables: []
70
+
71
+ extensions: []
72
+
73
+ extra_rdoc_files:
74
+ - History.txt
75
+ - Manifest.txt
76
+ - README.rdoc
77
+ files:
78
+ - History.txt
79
+ - Manifest.txt
80
+ - README.rdoc
81
+ - Rakefile
82
+ - lib/tmp_cache.rb
83
+ - lib/tmp_cache/cache.rb
84
+ - script/console
85
+ - script/destroy
86
+ - script/generate
87
+ - test/test_helper.rb
88
+ - test/test_tmp_cache.rb
89
+ - samples/sample.rb
90
+ - .gemtest
91
+ homepage: http://github.com/shokai/tmp_cache
92
+ licenses: []
93
+
94
+ post_install_message:
95
+ rdoc_options:
96
+ - --main
97
+ - README.rdoc
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project: tmp_cache
121
+ rubygems_version: 1.8.17
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: on memory cache.
125
+ test_files:
126
+ - test/test_helper.rb
127
+ - test/test_tmp_cache.rb