-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
150 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
# @api private | ||
# @since 0.3.1 | ||
module AnyCache::Patches | ||
# @since 0.3.1 | ||
require_relative 'patches/dalli_store' | ||
|
||
class << self | ||
# @param patch_series [Symbol, String] | ||
# @return [void] | ||
# | ||
# @raise [AnyCache::NonexistentPatchError] | ||
# | ||
# @api private | ||
# @since 0.3.1 | ||
def enable!(patch_series) | ||
case patch_series | ||
when :dalli_store, 'dalli_store' | ||
AnyCache::Patches::DalliStore.enable! | ||
else | ||
raise AnyCache::NonexistentPatchError, "Can't enable nonexistnet patch! (#{patch_series})" | ||
end | ||
end | ||
end | ||
|
||
# @api private | ||
# @since 0.3.1 | ||
module InterfaceAccessMixin | ||
# @param patch_series [Symbol, String] | ||
# @return [void] | ||
# | ||
# @see AnyCache::Patches#enable! | ||
# | ||
# @api private | ||
# @since 0.3.1 | ||
def enable_patch!(patch_series) | ||
AnyCache::Patches.enable!(patch_series) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
# @api private | ||
# @since 0.3.1 | ||
module AnyCache::Patches::DalliStore | ||
class << self | ||
# @return [void] | ||
# | ||
# @api private | ||
# @since 0.3.1 | ||
def enable! | ||
defined?(::Dalli) && | ||
defined?(::ActiveSupport::Cache::DalliStore) && | ||
Gem::Version.new(::Dalli::VERSION) <= Gem::Version.new('2.7.8') && | ||
::ActiveSupport::Cache::DalliStore.prepend(ActiveSupportFetchWithKey) | ||
end | ||
end | ||
|
||
# @api private | ||
# @since 0.3.1 | ||
module ActiveSupportFetchWithKey | ||
# NOTE: original fetch implementation with my own little fix (see #43 line of code below) | ||
# rubocop:disable all | ||
def fetch(name, options=nil) | ||
options ||= {} | ||
options[:cache_nils] = true if @options[:cache_nils] | ||
namespaced_name = namespaced_key(name, options) | ||
not_found = options[:cache_nils] ? Dalli::Server::NOT_FOUND : nil | ||
if block_given? | ||
entry = not_found | ||
unless options[:force] | ||
entry = instrument_with_log(:read, namespaced_name, options) do |payload| | ||
read_entry(namespaced_name, options).tap do |result| | ||
if payload | ||
payload[:super_operation] = :fetch | ||
payload[:hit] = not_found != result | ||
end | ||
end | ||
end | ||
end | ||
|
||
if not_found == entry | ||
result = instrument_with_log(:generate, namespaced_name, options) do |payload| | ||
# FIX: https://github.com/petergoldstein/dalli/pull/701 | ||
yield(name) | ||
# FIX: https://github.com/petergoldstein/dalli/pull/701 | ||
end | ||
write(name, result, options) | ||
result | ||
else | ||
instrument_with_log(:fetch_hit, namespaced_name, options) { |payload| } | ||
entry | ||
end | ||
else | ||
read(name, options) | ||
end | ||
end | ||
# rubocop:enable all | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class AnyCache | ||
# @return [String] | ||
# | ||
# @api public | ||
# @since 0.1.0 | ||
VERSION = '0.3.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
describe 'Patches interface' do | ||
describe 'patch activation' do | ||
it 'fails when the required patch does not exist' do | ||
random_nonexistent_patch_name = SecureRandom.hex(rand(1..4)).to_sym | ||
|
||
expect do | ||
AnyCache.enable_patch!(random_nonexistent_patch_name) | ||
end.to raise_error(AnyCache::NonexistentPatchError) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters