any_cache 0.3.0 → 0.3.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
  SHA256:
3
- metadata.gz: b4257f6b3fe2d927086723caf69eec54042cca687633f6737ee42f6604f434a8
4
- data.tar.gz: dd574909f6c2668f13f19e97cafb948dd1f8c5b4a284705a221b486ccdf29872
3
+ metadata.gz: ffa4d18aa6e7fdabf6cbb94da73a58c5daf2ced4aa74b28a7f16a73ed24cfc3e
4
+ data.tar.gz: 3a275c65d65426dfa41ba0fc00ac9b9de2da3684427e6ead5de9586021bcd574
5
5
  SHA512:
6
- metadata.gz: 88934a670129cf8a67177471884cc8aa493868c4a0ebe6e73899939d2ffd86c5877341965aba82860752e22fe72fb04abbc51c3e071d6f90507367581cba830c
7
- data.tar.gz: 676ed5568765a5916992333417503942cb545113aa30241c966b0723b7e521334991c56e008284e9f641db33e368509a8aa244a99658c07ca619ff67ce015c91
6
+ metadata.gz: 01e02bdaa716816ff2be016843337c1968a865b99ac98418ae2b7fa6bc5d7e32b9be986e48ffcd417b65fd6e88dc635b2087d14ee12b057c7e7b1cddf8e7706f
7
+ data.tar.gz: cf62adafcbf850fd47147e6b35f2dd9fc8adaf34735bebed6a66b86bb89bbc0d76d035774dfae885a708c5ef542684fea13891d06d7e93d2fb8e50d002d9c488
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.3.1] - 2018-10-08
5
+ ### Added
6
+ - patch interface `AnyCache.enable_patch!(:patch_series_name)`:
7
+ - `ActiveSupport::Cache::DalliStore` patch: now the `#fetch` method provides
8
+ a cache key attribute to the fallback proc (can be enabled via `.enable(:dalli_store)`);
9
+
4
10
  ## [0.3.0] - 2018-10-06
5
11
  ### Added
6
12
  - support for `ActiveSupport::Cache::DalliStore` client;
data/README.md CHANGED
@@ -60,6 +60,7 @@ require 'any_cache'
60
60
  - [Persist](#persist)
61
61
  - [Existence](#existence)
62
62
  - [Clear](#clear)
63
+ - [Roadmap](#roadmap)
63
64
 
64
65
  ---
65
66
 
@@ -195,6 +196,8 @@ require 'dalli'
195
196
  require 'active_support'
196
197
  require 'any_cache'
197
198
 
199
+ AnyCache.enable_patch!(:dalli_store)
200
+
198
201
  AnyCache.configure do |conf|
199
202
  conf.driver = :as_dalli_store
200
203
  conf.as_dalli_store.servers = ... # string or array of strings
data/lib/any_cache.rb CHANGED
@@ -14,12 +14,14 @@ class AnyCache
14
14
  require_relative 'any_cache/adapters'
15
15
  require_relative 'any_cache/logging'
16
16
  require_relative 'any_cache/delegation'
17
+ require_relative 'any_cache/patches'
17
18
 
18
19
  # @since 0.2.0
19
20
  include Qonfig::Configurable
20
-
21
21
  # @since 0.3.0
22
22
  include Delegation
23
+ # @since 0.3.1
24
+ extend Patches::InterfaceAccessMixin
23
25
 
24
26
  # @since 0.2.0
25
27
  # rubocop:disable Metrics/BlockLength
@@ -8,4 +8,7 @@ class AnyCache
8
8
 
9
9
  # @since 0.1.0
10
10
  UnsupportedDriverError = Class.new(Error)
11
+
12
+ # @since 0.3.1
13
+ NonexistentPatchError = Class.new(Error)
11
14
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.3.1
5
+ module AnyCache::Patches
6
+ # @since 0.3.1
7
+ require_relative 'patches/dalli_store'
8
+
9
+ class << self
10
+ # @param patch_series [Symbol, String]
11
+ # @return [void]
12
+ #
13
+ # @raise [AnyCache::NonexistentPatchError]
14
+ #
15
+ # @api private
16
+ # @since 0.3.1
17
+ def enable!(patch_series)
18
+ case patch_series
19
+ when :dalli_store, 'dalli_store'
20
+ AnyCache::Patches::DalliStore.enable!
21
+ else
22
+ raise AnyCache::NonexistentPatchError, "Can't enable nonexistnet patch! (#{patch_series})"
23
+ end
24
+ end
25
+ end
26
+
27
+ # @api private
28
+ # @since 0.3.1
29
+ module InterfaceAccessMixin
30
+ # @param patch_series [Symbol, String]
31
+ # @return [void]
32
+ #
33
+ # @see AnyCache::Patches#enable!
34
+ #
35
+ # @api private
36
+ # @since 0.3.1
37
+ def enable_patch!(patch_series)
38
+ AnyCache::Patches.enable!(patch_series)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.3.1
5
+ module AnyCache::Patches::DalliStore
6
+ class << self
7
+ # @return [void]
8
+ #
9
+ # @api private
10
+ # @since 0.3.1
11
+ def enable!
12
+ defined?(::Dalli) &&
13
+ defined?(::ActiveSupport::Cache::DalliStore) &&
14
+ Gem::Version.new(::Dalli::VERSION) <= Gem::Version.new('2.7.8') &&
15
+ ::ActiveSupport::Cache::DalliStore.prepend(ActiveSupportFetchWithKey)
16
+ end
17
+ end
18
+
19
+ # @api private
20
+ # @since 0.3.1
21
+ module ActiveSupportFetchWithKey
22
+ # NOTE: original fetch implementation with my own little fix (see #43 line of code below)
23
+ # rubocop:disable all
24
+ def fetch(name, options=nil)
25
+ options ||= {}
26
+ options[:cache_nils] = true if @options[:cache_nils]
27
+ namespaced_name = namespaced_key(name, options)
28
+ not_found = options[:cache_nils] ? Dalli::Server::NOT_FOUND : nil
29
+ if block_given?
30
+ entry = not_found
31
+ unless options[:force]
32
+ entry = instrument_with_log(:read, namespaced_name, options) do |payload|
33
+ read_entry(namespaced_name, options).tap do |result|
34
+ if payload
35
+ payload[:super_operation] = :fetch
36
+ payload[:hit] = not_found != result
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ if not_found == entry
43
+ result = instrument_with_log(:generate, namespaced_name, options) do |payload|
44
+ # FIX: https://github.com/petergoldstein/dalli/pull/701
45
+ yield(name)
46
+ # FIX: https://github.com/petergoldstein/dalli/pull/701
47
+ end
48
+ write(name, result, options)
49
+ result
50
+ else
51
+ instrument_with_log(:fetch_hit, namespaced_name, options) { |payload| }
52
+ entry
53
+ end
54
+ else
55
+ read(name, options)
56
+ end
57
+ end
58
+ # rubocop:enable all
59
+ end
60
+ end
61
+
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class AnyCache
4
+ # @return [String]
5
+ #
6
+ # @api public
4
7
  # @since 0.1.0
5
- VERSION = '0.3.0'
8
+ VERSION = '0.3.1'
6
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: any_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-06 00:00:00.000000000 Z
11
+ date: 2018-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -209,6 +209,8 @@ files:
209
209
  - lib/any_cache/logging.rb
210
210
  - lib/any_cache/logging/activity.rb
211
211
  - lib/any_cache/logging/logger.rb
212
+ - lib/any_cache/patches.rb
213
+ - lib/any_cache/patches/dalli_store.rb
212
214
  - lib/any_cache/version.rb
213
215
  homepage: https://github.com/0exp/any_cache
214
216
  licenses: