mini_memory_store 0.1.0 → 1.0.0
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/lib/mini_memory_store.rb +14 -14
- data/lib/mini_memory_store/version.rb +4 -0
- metadata +25 -96
- data/Gemfile +0 -7
- data/Gemfile.lock +0 -26
- data/Rakefile +0 -20
- data/Readme.md +0 -15
- data/VERSION +0 -1
- data/mini_memory_store.gemspec +0 -53
- data/spec/mini_memory_store_spec.rb +0 -59
- data/spec/spec_helper.rb +0 -2
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f2257c5c9e282097d2c81c3b4d2a70fbb8d3f325dca144c9101b7bae9d1916de
|
4
|
+
data.tar.gz: a98048deeedd8d0897f443dcd3132b3a688ee452344eff5184a47aabea6a8220
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 74f541768c40df7aef1673270a7f6ba0dd2fb33b6fd4385aa8d6df802b08979d76bf997d1a14e51316af3c29f01dee4b0a49e79c498894d0bf7f08cf7ae6673c
|
7
|
+
data.tar.gz: 87c45aa8d158066602c16fb66726deb29401f789ae8cef52a2522ba28a3a1a96609b1877be7315cd34bb03f137e0efcd0a8076c36d6ec9be2d158137e5df6a17
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (C) 2013 Michael Grosser <michael@grosser.it>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/mini_memory_store.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
class MiniMemoryStore
|
2
|
-
|
3
|
-
|
4
|
-
def initialize(options={})
|
5
|
-
@options = options
|
3
|
+
def initialize(expires_in:)
|
4
|
+
@expires_in = expires_in
|
6
5
|
@last_set = 0
|
7
6
|
end
|
8
7
|
|
9
8
|
def set(value)
|
10
|
-
@last_set =
|
9
|
+
@last_set = now
|
11
10
|
@value = value
|
12
11
|
end
|
13
12
|
|
@@ -19,15 +18,13 @@ class MiniMemoryStore
|
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
|
-
def cache
|
21
|
+
def cache
|
23
22
|
value = get
|
24
23
|
if value.nil?
|
25
|
-
value =
|
26
|
-
set
|
27
|
-
value
|
28
|
-
else
|
29
|
-
value
|
24
|
+
value = yield
|
25
|
+
set value
|
30
26
|
end
|
27
|
+
value
|
31
28
|
end
|
32
29
|
|
33
30
|
def clear
|
@@ -37,7 +34,10 @@ class MiniMemoryStore
|
|
37
34
|
private
|
38
35
|
|
39
36
|
def expired?
|
40
|
-
|
41
|
-
|
37
|
+
(now - @expires_in) >= @last_set
|
38
|
+
end
|
39
|
+
|
40
|
+
def now
|
41
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
42
42
|
end
|
43
|
-
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,117 +1,46 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_memory_store
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Michael Grosser
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
default_executable:
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
-
none: false
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
hash: 3
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
version: "0"
|
31
|
-
name: rake
|
32
|
-
prerelease: false
|
33
|
-
type: :development
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
-
none: false
|
38
|
-
requirements:
|
39
|
-
- - ~>
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
hash: 7
|
42
|
-
segments:
|
43
|
-
- 2
|
44
|
-
version: "2"
|
45
|
-
name: rspec
|
46
|
-
prerelease: false
|
47
|
-
type: :development
|
48
|
-
version_requirements: *id002
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
-
none: false
|
52
|
-
requirements:
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
hash: 3
|
56
|
-
segments:
|
57
|
-
- 0
|
58
|
-
version: "0"
|
59
|
-
name: jeweler
|
60
|
-
prerelease: false
|
61
|
-
type: :development
|
62
|
-
version_requirements: *id003
|
11
|
+
date: 2019-04-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
63
13
|
description:
|
64
14
|
email: michael@grosser.it
|
65
15
|
executables: []
|
66
|
-
|
67
16
|
extensions: []
|
68
|
-
|
69
17
|
extra_rdoc_files: []
|
70
|
-
|
71
|
-
|
72
|
-
- Gemfile
|
73
|
-
- Gemfile.lock
|
74
|
-
- Rakefile
|
75
|
-
- Readme.md
|
76
|
-
- VERSION
|
18
|
+
files:
|
19
|
+
- MIT-LICENSE
|
77
20
|
- lib/mini_memory_store.rb
|
78
|
-
- mini_memory_store.
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
licenses: []
|
84
|
-
|
21
|
+
- lib/mini_memory_store/version.rb
|
22
|
+
homepage: https://github.com/grosser/mini_memory_store
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
85
26
|
post_install_message:
|
86
27
|
rdoc_options: []
|
87
|
-
|
88
|
-
require_paths:
|
28
|
+
require_paths:
|
89
29
|
- lib
|
90
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
-
|
92
|
-
requirements:
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
93
32
|
- - ">="
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
version: "0"
|
99
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
-
none: false
|
101
|
-
requirements:
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 2.3.0
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
102
37
|
- - ">="
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
|
105
|
-
segments:
|
106
|
-
- 0
|
107
|
-
version: "0"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
108
40
|
requirements: []
|
109
|
-
|
110
41
|
rubyforge_project:
|
111
|
-
rubygems_version:
|
42
|
+
rubygems_version: 2.7.6
|
112
43
|
signing_key:
|
113
|
-
specification_version:
|
44
|
+
specification_version: 4
|
114
45
|
summary: Store a single value in memory with expiration
|
115
|
-
test_files:
|
116
|
-
- spec/mini_memory_store_spec.rb
|
117
|
-
- spec/spec_helper.rb
|
46
|
+
test_files: []
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
diff-lcs (1.1.2)
|
5
|
-
git (1.2.5)
|
6
|
-
jeweler (1.5.2)
|
7
|
-
bundler (~> 1.0.0)
|
8
|
-
git (>= 1.2.5)
|
9
|
-
rake
|
10
|
-
rake (0.8.7)
|
11
|
-
rspec (2.3.0)
|
12
|
-
rspec-core (~> 2.3.0)
|
13
|
-
rspec-expectations (~> 2.3.0)
|
14
|
-
rspec-mocks (~> 2.3.0)
|
15
|
-
rspec-core (2.3.1)
|
16
|
-
rspec-expectations (2.3.0)
|
17
|
-
diff-lcs (~> 1.1.2)
|
18
|
-
rspec-mocks (2.3.0)
|
19
|
-
|
20
|
-
PLATFORMS
|
21
|
-
ruby
|
22
|
-
|
23
|
-
DEPENDENCIES
|
24
|
-
jeweler
|
25
|
-
rake
|
26
|
-
rspec (~> 2)
|
data/Rakefile
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
task :default => :spec
|
2
|
-
require "rspec/core/rake_task"
|
3
|
-
RSpec::Core::RakeTask.new(:spec) do |t|
|
4
|
-
t.rspec_opts = '--backtrace --color'
|
5
|
-
end
|
6
|
-
|
7
|
-
begin
|
8
|
-
require 'jeweler'
|
9
|
-
Jeweler::Tasks.new do |gem|
|
10
|
-
gem.name = 'mini_memory_store'
|
11
|
-
gem.summary = "Store a single value in memory with expiration"
|
12
|
-
gem.email = "michael@grosser.it"
|
13
|
-
gem.homepage = "http://github.com/grosser/#{gem.name}"
|
14
|
-
gem.authors = ["Michael Grosser"]
|
15
|
-
end
|
16
|
-
|
17
|
-
Jeweler::GemcutterTasks.new
|
18
|
-
rescue LoadError
|
19
|
-
puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
|
20
|
-
end
|
data/Readme.md
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
Store a single value in memory with expiration
|
2
|
-
|
3
|
-
Install
|
4
|
-
=======
|
5
|
-
sudo gem install mini_memory_store
|
6
|
-
|
7
|
-
Usage
|
8
|
-
=====
|
9
|
-
CODE_EXAMPLE
|
10
|
-
|
11
|
-
Author
|
12
|
-
======
|
13
|
-
[Michael Grosser](http://grosser.it)
|
14
|
-
grosser.michael@gmail.com
|
15
|
-
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.0
|
data/mini_memory_store.gemspec
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{mini_memory_store}
|
8
|
-
s.version = "0.1.0"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Michael Grosser"]
|
12
|
-
s.date = %q{2010-12-22}
|
13
|
-
s.email = %q{michael@grosser.it}
|
14
|
-
s.files = [
|
15
|
-
"Gemfile",
|
16
|
-
"Gemfile.lock",
|
17
|
-
"Rakefile",
|
18
|
-
"Readme.md",
|
19
|
-
"VERSION",
|
20
|
-
"lib/mini_memory_store.rb",
|
21
|
-
"mini_memory_store.gemspec",
|
22
|
-
"spec/mini_memory_store_spec.rb",
|
23
|
-
"spec/spec_helper.rb"
|
24
|
-
]
|
25
|
-
s.homepage = %q{http://github.com/grosser/mini_memory_store}
|
26
|
-
s.require_paths = ["lib"]
|
27
|
-
s.rubygems_version = %q{1.3.7}
|
28
|
-
s.summary = %q{Store a single value in memory with expiration}
|
29
|
-
s.test_files = [
|
30
|
-
"spec/mini_memory_store_spec.rb",
|
31
|
-
"spec/spec_helper.rb"
|
32
|
-
]
|
33
|
-
|
34
|
-
if s.respond_to? :specification_version then
|
35
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
36
|
-
s.specification_version = 3
|
37
|
-
|
38
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
39
|
-
s.add_development_dependency(%q<rake>, [">= 0"])
|
40
|
-
s.add_development_dependency(%q<rspec>, ["~> 2"])
|
41
|
-
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
42
|
-
else
|
43
|
-
s.add_dependency(%q<rake>, [">= 0"])
|
44
|
-
s.add_dependency(%q<rspec>, ["~> 2"])
|
45
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
46
|
-
end
|
47
|
-
else
|
48
|
-
s.add_dependency(%q<rake>, [">= 0"])
|
49
|
-
s.add_dependency(%q<rspec>, ["~> 2"])
|
50
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require File.expand_path('spec/spec_helper')
|
2
|
-
|
3
|
-
describe MiniMemoryStore do
|
4
|
-
let(:store){ MiniMemoryStore.new }
|
5
|
-
|
6
|
-
it "has a VERSION" do
|
7
|
-
MiniMemoryStore::VERSION.should =~ /^\d+\.\d+\.\d+$/
|
8
|
-
end
|
9
|
-
|
10
|
-
it "is nil when not set" do
|
11
|
-
store.get.should == nil
|
12
|
-
end
|
13
|
-
|
14
|
-
it "can store a value" do
|
15
|
-
store.set 1
|
16
|
-
store.get.should == 1
|
17
|
-
end
|
18
|
-
|
19
|
-
it "can cache a value" do
|
20
|
-
store.cache{1}.should == 1
|
21
|
-
store.cache{2}.should == 1
|
22
|
-
end
|
23
|
-
|
24
|
-
it "can cache false" do
|
25
|
-
store.cache{false}.should == false
|
26
|
-
store.cache{1}.should == false
|
27
|
-
end
|
28
|
-
|
29
|
-
it "does not cache nil" do
|
30
|
-
store.cache{nil}.should == nil
|
31
|
-
store.cache{1}.should == 1
|
32
|
-
end
|
33
|
-
|
34
|
-
it "clears" do
|
35
|
-
store.set 1
|
36
|
-
store.clear
|
37
|
-
store.get.should == nil
|
38
|
-
end
|
39
|
-
|
40
|
-
it "does not expire" do
|
41
|
-
store.set 1
|
42
|
-
sleep 1
|
43
|
-
store.get.should == 1
|
44
|
-
end
|
45
|
-
|
46
|
-
it "expires after given time" do
|
47
|
-
store = MiniMemoryStore.new(:expires_in => 1)
|
48
|
-
store.set 1
|
49
|
-
store.get.should == 1
|
50
|
-
sleep 1
|
51
|
-
store.get.should == nil
|
52
|
-
end
|
53
|
-
|
54
|
-
it "expires immediately with expires_in => 0" do
|
55
|
-
store = MiniMemoryStore.new(:expires_in => 0)
|
56
|
-
store.set 1
|
57
|
-
store.get.should == nil
|
58
|
-
end
|
59
|
-
end
|
data/spec/spec_helper.rb
DELETED