filecache 1.0 → 1.0.1

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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/lib/filecache.rb +11 -0
  3. metadata +26 -37
  4. data/COPYING +0 -24
  5. data/README +0 -37
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3476b99d5e717fbec070540e3227bbdb9d5e4b6c
4
+ data.tar.gz: d144dc736511955e3f47196da3be61150f5d938a
5
+ SHA512:
6
+ metadata.gz: 54373883d9a35330c6c1a9ff958490b5314629a6cbad2531aac102c6a7de9075c6de17ad74d19657236d29dc331430aded2f5b9c503b9fca78ddce36be45d942
7
+ data.tar.gz: 7ab4a33c3cbbdb41c70e16b0596a0dddb5c54f8b59248dd687a8e7ef441975080054019a8c08e2bc7d2e910c78d2bb5b82e6c9b211307ab073cafcc351a4540a
data/lib/filecache.rb CHANGED
@@ -54,6 +54,17 @@ class FileCache
54
54
  end
55
55
  end
56
56
 
57
+ # Return the value for the specified key from the cache if the key exists in the
58
+ # cache, otherwise set the value returned by the block. Returns the value if found
59
+ # or the value from calling the block that was set.
60
+ def get_or_set(key)
61
+ value = get(key)
62
+ return value if value
63
+ value = yield
64
+ set(key, value)
65
+ value
66
+ end
67
+
57
68
  # Delete the value for the given key from the cache
58
69
  def delete(key)
59
70
  FileUtils.rm(get_path(key))
metadata CHANGED
@@ -1,57 +1,46 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: filecache
3
- version: !ruby/object:Gem::Version
4
- version: "1.0"
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Simon Whitaker
8
- autorequire: filecache
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2009-08-29 00:00:00 +01:00
13
- default_executable:
11
+ date: 2016-07-20 00:00:00.000000000 Z
14
12
  dependencies: []
15
-
16
13
  description:
17
14
  email: sw@netcetera.org
18
15
  executables: []
19
-
20
16
  extensions: []
21
-
22
- extra_rdoc_files:
23
- - README
24
- - COPYING
25
- files:
17
+ extra_rdoc_files: []
18
+ files:
26
19
  - lib/filecache.rb
27
20
  - tests/test_filecache.rb
28
- - README
29
- - COPYING
30
- has_rdoc: true
31
- homepage: http://netcetera.org
21
+ homepage:
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
32
25
  post_install_message:
33
26
  rdoc_options: []
34
-
35
- require_paths:
27
+ require_paths:
36
28
  - lib
37
- required_ruby_version: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: "0"
42
- version:
43
- required_rubygems_version: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: "0"
48
- version:
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
49
39
  requirements: []
50
-
51
40
  rubyforge_project: filecache
52
- rubygems_version: 1.2.0
41
+ rubygems_version: 2.0.14.1
53
42
  signing_key:
54
- specification_version: 2
43
+ specification_version: 4
55
44
  summary: A file-based caching library
56
- test_files:
45
+ test_files:
57
46
  - tests/test_filecache.rb
data/COPYING DELETED
@@ -1,24 +0,0 @@
1
- FileCache is distributed under the MIT license
2
-
3
- Copyright (c) 2008 Simon Whitaker <mailto:sw@netcetera.org>
4
-
5
- Permission is hereby granted, free of charge, to any person
6
- obtaining a copy of this software and associated documentation
7
- files (the "Software"), to deal in the Software without
8
- restriction, including without limitation the rights to use,
9
- copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the
11
- Software is furnished to do so, subject to the following
12
- conditions:
13
-
14
- The above copyright notice and this permission notice shall be
15
- included in all copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
- OTHER DEALINGS IN THE SOFTWARE.
data/README DELETED
@@ -1,37 +0,0 @@
1
- = FileCache
2
-
3
- FileCache is a file-based caching library for Ruby. It's
4
- available for download from RubyForge[http://rubyforge.org/projects/filecache/]
5
-
6
- = Installation
7
-
8
- gem install -r filecache
9
-
10
- (On a Unix-like system you'll probably want to run that with sudo.)
11
-
12
- = Synopsis
13
-
14
- require 'rubygems'
15
- require 'filecache'
16
-
17
- cache = FileCache.new
18
- cache.set(:key, "value")
19
- puts cache.get(:key) # "value"
20
- cache.delete(:key)
21
- puts cache.get(:key) # nil
22
-
23
- # create a new cache called "my-cache", rooted in /home/simon/caches
24
- # with an expiry time of 30 seconds, and a file hierarchy three
25
- # directories deep
26
- cache = FileCache.new("my-cache", "/home/simon/caches", 30, 3)
27
- cache.put("joe", "bloggs")
28
- puts(cache.get("joe")) # "bloggs"
29
- sleep 30
30
- puts(cache.get("joe")) # nil
31
-
32
-
33
- = Copyright
34
-
35
- Copyright 2008 Simon Whitaker <mailto:sw@netcetera.org>
36
-
37
- See COPYING for license.