timedcache 0.2 → 0.3
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/README.txt +9 -2
- data/lib/timedcache.rb +4 -6
- data/spec/timed_cache_spec.rb +4 -4
- metadata +5 -4
data/History.txt
CHANGED
data/README.txt
CHANGED
@@ -11,7 +11,7 @@ If you attempt to retrieve the object within the specified timeout
|
|
11
11
|
period, the object will be returned. If the timeout period has elapsed,
|
12
12
|
the TimedCache will return nil.
|
13
13
|
|
14
|
-
== FEATURES
|
14
|
+
== FEATURES:
|
15
15
|
|
16
16
|
* Memory or file-based data stores available.
|
17
17
|
* Thread safety.
|
@@ -31,11 +31,18 @@ the TimedCache will return nil.
|
|
31
31
|
|
32
32
|
sudo gem timedcache
|
33
33
|
|
34
|
+
== SOURCE:
|
35
|
+
|
36
|
+
You can browse the source control history or get a copy of the git
|
37
|
+
repository by going to:
|
38
|
+
|
39
|
+
* http://github.com/nickpad/timedcache/tree/master
|
40
|
+
|
34
41
|
== LICENSE:
|
35
42
|
|
36
43
|
(The MIT License)
|
37
44
|
|
38
|
-
Copyright (c) 2008 Nicholas Dainty
|
45
|
+
Copyright (c) 2008, 2009 Nicholas Dainty
|
39
46
|
|
40
47
|
Permission is hereby granted, free of charge, to any person obtaining
|
41
48
|
a copy of this software and associated documentation files (the
|
data/lib/timedcache.rb
CHANGED
@@ -46,7 +46,7 @@ require "monitor"
|
|
46
46
|
#
|
47
47
|
# Note that objects that cannot be marshalled (e.g. a Proc) can't be stored using the file-based cache.
|
48
48
|
class TimedCache
|
49
|
-
VERSION = "0.
|
49
|
+
VERSION = "0.3"
|
50
50
|
|
51
51
|
attr_reader :default_timeout
|
52
52
|
|
@@ -79,10 +79,7 @@ class TimedCache
|
|
79
79
|
# is not present, +nil+ is returned.
|
80
80
|
#
|
81
81
|
# Optionally, a block can be given. The result of evaluating the block will
|
82
|
-
# be substituted as the cache value, if the cache has expired.
|
83
|
-
# useful when using a file-based cache from multiple ruby processes, as it
|
84
|
-
# will prevent your application from making multiple simultaneous attempts to
|
85
|
-
# re-populate the cache.
|
82
|
+
# be substituted as the cache value, if the cache has expired.
|
86
83
|
#
|
87
84
|
# e.g.:
|
88
85
|
#
|
@@ -214,7 +211,8 @@ class TimedCache
|
|
214
211
|
end
|
215
212
|
|
216
213
|
def expired?
|
217
|
-
if @frozen
|
214
|
+
if @frozen
|
215
|
+
false
|
218
216
|
else
|
219
217
|
(Time.now.utc - @timeout) > @created_at
|
220
218
|
end
|
data/spec/timed_cache_spec.rb
CHANGED
@@ -3,13 +3,13 @@ require File.join(File.dirname(__FILE__), "../lib/timedcache")
|
|
3
3
|
$filename = File.join(File.dirname(__FILE__), "specs.db")
|
4
4
|
|
5
5
|
describe "Adding and retrieving objects from the cache" do
|
6
|
-
|
6
|
+
before(:each) do
|
7
7
|
@memory_cache = TimedCache.new
|
8
8
|
@file_cache = TimedCache.new(:type => :file, :filename => $filename)
|
9
9
|
@caches = [@memory_cache, @file_cache]
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
after do
|
13
13
|
File.delete($filename)
|
14
14
|
end
|
15
15
|
|
@@ -96,7 +96,7 @@ describe "Specifying a default timeout" do
|
|
96
96
|
cache = TimedCache.new(:default_timeout => 20)
|
97
97
|
cache.default_timeout.should == 20
|
98
98
|
cache.put("alternative_timeout", "2 minutes", 120)
|
99
|
-
cache.instance_variable_get(:@store).instance_variable_get(
|
100
|
-
|
99
|
+
cache.instance_variable_get(:@store).instance_variable_get(:@cache)["alternative_timeout"].
|
100
|
+
instance_variable_get(:@timeout).should == 120
|
101
101
|
end
|
102
102
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timedcache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.3"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas Dainty
|
@@ -9,17 +9,18 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-03-28 23:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: hoe
|
17
|
+
type: :development
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
20
21
|
- - ">="
|
21
22
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.
|
23
|
+
version: 1.8.2
|
23
24
|
version:
|
24
25
|
description: TimedCache implements a cache in which you can place objects and specify a timeout value. If you attempt to retrieve the object within the specified timeout period, the object will be returned. If the timeout period has elapsed, the TimedCache will return nil.
|
25
26
|
email: nick@npad.co.uk
|
@@ -63,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
64
|
requirements: []
|
64
65
|
|
65
66
|
rubyforge_project: timedcache
|
66
|
-
rubygems_version: 1.
|
67
|
+
rubygems_version: 1.3.1
|
67
68
|
signing_key:
|
68
69
|
specification_version: 2
|
69
70
|
summary: A very simple time-based object cache.
|