mrcr-cache 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50c58c6d0518cc3345cc446309997c0c7d05d6a4
4
- data.tar.gz: cb4d12a4b0d4c035b641036027bbe1103b296d40
3
+ metadata.gz: 7b7da641b1029613733d14a8823c39bdbcb1abe7
4
+ data.tar.gz: 6b7e4013b3074502cfbace458b58937d479a5a05
5
5
  SHA512:
6
- metadata.gz: 981b098fd102a8fad6daec312eebf94b1a3a05def3a0940681788f01dc071dd5a6645c8a77b1ea4c1997624b252efd3137fa999d5fc4503bf30260cc796a6946
7
- data.tar.gz: dd07f013f3f072dea0a9eb9de4d937316ae3adff08d07bf6d28be972a725cad9dda3dc9a18b2ea5a4d90bfffecb8a6fa5fa31794ee9848f7da9964afa9cd2a65
6
+ metadata.gz: 5091c9e32958be89b49fe40c0928258476daefe273962c3598763dfdabee4904901b73afe5e96d4e155f6d826344c04c39dbc9e9bc20d9f30a25b49d3a09a892
7
+ data.tar.gz: 6c7741baeca70826d5c7bc265819f929a234f46c2725141646dcb55ffa6e10a24f53cd650a641673e01fe14ef060c8385b427628c04ce2e84d4440e8d6d4b679
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ [![Gem Version](https://badge.fury.io/rb/mrcr-cache.svg)](https://badge.fury.io/rb/mrcr-cache)
2
+ [![Build Status](https://travis-ci.org/merqlove/mrcr-cache.svg?branch=master)](https://travis-ci.org/merqlove/mrcr-cache)
3
+
1
4
  # Mrcr::Cache
2
5
 
3
6
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mrcr/cache`. To experiment with that code, run `bin/console` for an interactive prompt.
data/lib/mrcr/cache.rb CHANGED
@@ -11,7 +11,8 @@ module Mrcr
11
11
  # extend Mrcr::Cache
12
12
  #
13
13
  # def heavy_computation(arg1, arg2)
14
- # fetch_or_store(arg1, arg2) { arg1 ^ arg2 }
14
+ # fetch_or_store(arg1) { arg1 ^ arg2 }
15
+ # fetch(arg1, nil)
15
16
  # end
16
17
  # end
17
18
  #
@@ -45,8 +46,22 @@ module Mrcr
45
46
  # they are always the same instances, otherwise you introduce a memory leak
46
47
  #
47
48
  # @return [Object] block's return value (cached for subsequent calls with the same argument values)
48
- def fetch_or_store(*args, &block)
49
- cache.fetch_or_store(args.hash, &block)
49
+ def fetch_or_store(key, &block)
50
+ cache.fetch_or_store(key.hash, &block)
51
+ end
52
+
53
+ # Caches a result of the block evaluation
54
+ #
55
+ # @param [Array<Object>] args List of hashable objects
56
+ # @yield An arbitrary block
57
+ #
58
+ # @note beware Proc instance hashes are not equal, i.e. -> { 1 }.hash != -> { 1 }.hash,
59
+ # this means you shouldn't pass Procs in args unless you're sure
60
+ # they are always the same instances, otherwise you introduce a memory leak
61
+ #
62
+ # @return [Object] block's return value (cached for subsequent calls with the same argument values)
63
+ def fetch(key, default = nil)
64
+ cache.fetch(key.hash, default)
50
65
  end
51
66
 
52
67
  # Instance methods
@@ -57,8 +72,19 @@ module Mrcr
57
72
  # @yield An arbitrary block
58
73
  #
59
74
  # @return [Object] block's return value
60
- def fetch_or_store(*args, &block)
61
- self.class.fetch_or_store(*args, &block)
75
+ def fetch_or_store(key, &block)
76
+ self.class.fetch_or_store(key, &block)
77
+ end
78
+
79
+ # Delegates call to the class-level method
80
+ #
81
+ # @param [Object] value List of hashable objects
82
+ # @param [Object] default List of hashable objects
83
+ # @yield An arbitrary block
84
+ #
85
+ # @return [Object] block's return value
86
+ def fetch(key, default = nil)
87
+ self.class.fetch(key, default)
62
88
  end
63
89
  end
64
90
  end
@@ -1,5 +1,5 @@
1
1
  module Mrcr
2
2
  module Cache
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.1.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mrcr-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Merkulov