-
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
56 changed files
with
2,051 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,6 @@ AllCops: | |
- Gemfile | ||
- Rakefile | ||
- any_cache.gemspec | ||
|
||
Layout/MultilineOperationIndentation: | ||
Enabled: false |
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,5 +1,80 @@ | ||
sudo: false | ||
language: ruby | ||
rvm: | ||
- 2.5.1 | ||
before_install: gem install bundler -v 1.16.2 | ||
sudo: false | ||
before_install: gem install bundler | ||
cache: bundler | ||
script: bundle exec rspec | ||
matrix: | ||
fast_finish: true | ||
include: | ||
- rvm: 2.3.7 | ||
gemfile: gemfiles/active_support.gemfile | ||
env: TEST_AS_MEMORY_STORE_CACHE=true | ||
- rvm: 2.4.4 | ||
gemfile: gemfiles/active_support.gemfile | ||
env: TEST_AS_MEMORY_STORE_CACHE=true | ||
- rvm: 2.5.1 | ||
gemfile: gemfiles/active_support.gemfile | ||
env: TEST_AS_MEMORY_STORE_CACHE=true | ||
- rvm: ruby-head | ||
gemfile: gemfiles/active_support.gemfile | ||
env: TEST_AS_MEMORY_STORE_CACHE=true | ||
- rvm: 2.3.7 | ||
gemfile: gemfiles/active_support.gemfile | ||
env: TEST_AS_FILE_STORE_CACHE=true | ||
- rvm: 2.4.4 | ||
gemfile: gemfiles/active_support.gemfile | ||
env: TEST_AS_FILE_STORE_CACHE=true | ||
- rvm: 2.5.1 | ||
gemfile: gemfiles/active_support.gemfile | ||
env: TEST_AS_FILE_STORE_CACHE=true | ||
- rvm: ruby-head | ||
gemfile: gemfiles/active_support.gemfile | ||
env: TEST_AS_FILE_STORE_CACHE=true | ||
- rvm: 2.3.7 | ||
gemfile: gemfiles/active_support_with_redis.gemfile | ||
env: TEST_AS_REDIS_CACHE_STORE_CACHE=true | ||
- rvm: 2.4.4 | ||
gemfile: gemfiles/active_support_with_redis.gemfile | ||
env: TEST_AS_REDIS_CACHE_STORE_CACHE=true | ||
- rvm: 2.5.1 | ||
gemfile: gemfiles/active_support_with_redis.gemfile | ||
env: TEST_AS_REDIS_CACHE_STORE_CACHE=true | ||
- rvm: ruby-head | ||
gemfile: gemfiles/active_support_with_redis.gemfile | ||
env: TEST_AS_REDIS_CACHE_STORE_CACHE=true | ||
- rvm: 2.3.7 | ||
gemfile: gemfiles/dalli.gemfile | ||
env: TEST_DALLI_CACHE=true | ||
- rvm: 2.4.4 | ||
gemfile: gemfiles/dalli.gemfile | ||
env: TEST_DALLI_CACHE=true | ||
- rvm: 2.5.1 | ||
gemfile: gemfiles/dalli.gemfile | ||
env: TEST_DALLI_CACHE=true | ||
- rvm: ruby-head | ||
gemfile: gemfiles/dalli.gemfile | ||
env: TEST_DALLI_CACHE=true | ||
- rvm: 2.3.7 | ||
gemfile: gemfiles/redis_store.gemfile | ||
env: TEST_REDIS_STORE_CACHE=true | ||
- rvm: 2.4.4 | ||
gemfile: gemfiles/redis_store.gemfile | ||
env: TEST_REDIS_STORE_CACHE=true | ||
- rvm: 2.5.1 | ||
gemfile: gemfiles/redis_store.gemfile | ||
env: TEST_REDIS_STORE_CACHE=true | ||
- rvm: ruby-head | ||
gemfile: gemfiles/redis_store.gemfile | ||
env: TEST_REDIS_STORE_CACHE=true | ||
- rvm: 2.3.7 | ||
gemfile: gemfiles/redis_store.gemfile | ||
env: TEST_REDIS_CACHE=true | ||
- rvm: 2.4.4 | ||
gemfile: gemfiles/redis_store.gemfile | ||
env: TEST_REDIS_CACHE=true | ||
- rvm: 2.5.1 | ||
gemfile: gemfiles/redis_store.gemfile | ||
env: TEST_REDIS_CACHE=true | ||
- rvm: ruby-head | ||
gemfile: gemfiles/redis_store.gemfile | ||
env: TEST_REDIS_CACHE=true |
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 |
---|---|---|
|
@@ -4,5 +4,5 @@ | |
require 'bundler/setup' | ||
require 'any_cache' | ||
|
||
require "pry" | ||
require 'pry' | ||
Pry.start |
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,119 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require 'pathname' | ||
require 'optparse' | ||
|
||
module AnyCacheSpecRunner | ||
extend self | ||
|
||
def expand_gemfile_path(gemfile_name) | ||
File.expand_path( | ||
File.join('..', '..', 'gemfiles', gemfile_name), | ||
Pathname.new(__FILE__).realpath | ||
) | ||
end | ||
|
||
GEMFILES = { | ||
redis: expand_gemfile_path('redis.gemfile'), | ||
redis_store: expand_gemfile_path('redis_store.gemfile'), | ||
dalli: expand_gemfile_path('dalli.gemfile'), | ||
active_support_with_redis: expand_gemfile_path('active_support_with_redis.gemfile'), | ||
active_support: expand_gemfile_path('active_support.gemfile') | ||
}.freeze | ||
|
||
# rubocop:disable Metrics/MethodLength, Metrics/BlockLength | ||
def run! | ||
OptionParser.new do |opts| | ||
opts.banner = 'Usage: bin/rspec [options]' | ||
|
||
opts.on( | ||
'--test-redis', | ||
'Run specs with Redis cache storage' | ||
) { run_redis_cache_specs! } | ||
|
||
opts.on( | ||
'--test-redis-store', | ||
'Run specs with Redis::Store cache storage' | ||
) { run_redis_store_cache_specs! } | ||
|
||
opts.on( | ||
'--test-dalli', | ||
'Run specs with Dalli spec storage' | ||
) { run_dalli_cache_specs! } | ||
|
||
opts.on( | ||
'--test-as-redis-cache-store', | ||
'Run specs with ActiveSupport::Cache::RedisCacheStore cache storage' | ||
) { run_as_redis_cache_store_cache_specs! } | ||
|
||
opts.on( | ||
'--test-as-file-store', | ||
'Run specs with ActiveSupport::Cache::FileStore cache storage' | ||
) { run_as_file_store_cache_specs! } | ||
|
||
opts.on( | ||
'--test-as-memory-store', | ||
'Run specs with ActiveSupport::Cache::MemoryStore cache storage' | ||
) { run_as_memory_store_cache_specs! } | ||
|
||
opts.on( | ||
'-h', '--help', | ||
'Show this message' | ||
) { puts opts } | ||
end.parse! | ||
end | ||
# rubocop:enable Metrics/MethodLength, Metrics/BlockLength | ||
|
||
private | ||
|
||
def run_redis_cache_specs! | ||
ENV['TEST_REDIS_CACHE'] = 'true' | ||
ENV['BUNDLE_GEMFILE'] = GEMFILES[:redis] | ||
|
||
run_tests! | ||
end | ||
|
||
def run_redis_store_cache_specs! | ||
ENV['TEST_REDIS_STORE_CACHE'] = 'true' | ||
ENV['BUNDLE_GEMFILE'] = GEMFILES[:redis_store] | ||
|
||
run_tests! | ||
end | ||
|
||
def run_dalli_cache_specs! | ||
ENV['TEST_DALLI_CACHE'] = 'true' | ||
ENV['BUNDLE_GEMFILE'] = GEMFILES[:dalli] | ||
|
||
run_tests! | ||
end | ||
|
||
def run_as_redis_cache_store_cache_specs! | ||
ENV['TEST_AS_REDIS_CACHE_STORE_CACHE'] = 'true' | ||
ENV['BUNDLE_GEMFILE'] = GEMFILES[:active_support_with_redis] | ||
|
||
run_tests! | ||
end | ||
|
||
def run_as_file_store_cache_specs! | ||
ENV['TEST_AS_FILE_STORE_CACHE'] = 'true' | ||
ENV['BUNDLE_GEMFILE'] = GEMFILES[:active_support] | ||
|
||
run_tests! | ||
end | ||
|
||
def run_as_memory_store_cache_specs! | ||
ENV['TEST_AS_MEMORY_STORE_CACHE'] = 'true' | ||
ENV['BUNDLE_GEMFILE'] = GEMFILES[:active_support] | ||
|
||
run_tests! | ||
end | ||
|
||
def run_tests! | ||
require 'rubygems' | ||
require 'bundler/setup' | ||
load Gem.bin_path('rspec-core', 'rspec') | ||
end | ||
end | ||
|
||
AnyCacheSpecRunner.run! |
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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
|
||
gem 'activesupport', '~> 5.2' | ||
|
||
gemspec path: '..' |
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,8 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
|
||
gem 'redis', '~> 4.0' | ||
gem 'activesupport', '~> 5.2' | ||
|
||
gemspec path: '..' |
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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
|
||
gem 'dalli', '~> 2.7' | ||
|
||
gemspec path: '..' |
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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
|
||
gem 'redis', '~> 4.0' | ||
|
||
gemspec path: '..' |
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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
|
||
gem 'redis-store', '~> 1.5' | ||
|
||
gemspec path: '..' |
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,8 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'any_cache/version' | ||
require 'securerandom' | ||
require 'qonfig' | ||
require 'concurrent/atomic/reentrant_read_write_lock' | ||
|
||
# @api public | ||
# @since 0.1.0 | ||
module AnyCache | ||
class AnyCache | ||
require_relative 'any_cache/version' | ||
require_relative 'any_cache/adapters' | ||
|
||
# @since 0.1.0 | ||
extend Forwardable | ||
|
||
class << self | ||
# @param driver [Object] | ||
# @return [AnyCache] | ||
# | ||
# @api private | ||
# @since 0.1.0 | ||
def build(driver) | ||
new(Adapters.build(driver)) | ||
end | ||
end | ||
|
||
# @since 0.1.0 | ||
def_delegators :adapter, :read, :write, :delete, :increment, :decrement, :re_expire, :clear | ||
|
||
# @return [AnyCache::Adapters::Basic] | ||
# | ||
# @api private | ||
# @since 0.1.0 | ||
attr_reader :adapter | ||
|
||
# @param adapter [AnyCache::Adapters::Basic] | ||
# @return [void] | ||
# | ||
# @api private | ||
# @since 0.1.0 | ||
def initialize(adapter) | ||
@adapter = adapter | ||
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,40 @@ | ||
# frozen_string_literal: true | ||
|
||
# @api private | ||
# @since 0.1.0 | ||
module AnyCache::Adapters | ||
require_relative 'adapters/basic' | ||
require_relative 'adapters/delegator' | ||
require_relative 'adapters/dalli' | ||
require_relative 'adapters/redis' | ||
require_relative 'adapters/redis_store' | ||
require_relative 'adapters/active_support_naive_store' | ||
require_relative 'adapters/active_support_file_store' | ||
require_relative 'adapters/active_support_redis_cache_store' | ||
require_relative 'adapters/active_support_memory_store' | ||
|
||
class << self | ||
# @param driver [Object] | ||
# @return [AnyCache::Adapters::Basic] | ||
# | ||
# @raise [AnyCache::UnsupportedCacheDriverError] | ||
# | ||
# @api private | ||
# @since 0.1.0 | ||
# rubocop:disable Metrics/LineLength | ||
def build(driver) | ||
case | ||
when RedisStore.supported_driver?(driver) then RedisStore.new(driver) | ||
when Redis.supported_driver?(driver) then Redis.new(driver) | ||
when Dalli.supported_driver?(driver) then Dalli.new(driver) | ||
when ActiveSupportRedisCacheStore.supported_driver?(driver) then ActiveSupportRedisCacheStore.new(driver) | ||
when ActiveSupportMemoryStore.supported_driver?(driver) then ActiveSupportMemoryStore.new(driver) | ||
when ActiveSupportFileStore.supported_driver?(driver) then ActiveSupportFileStore.new(driver) | ||
when Delegator.supported_driver?(driver) then Delegator.new(driver) | ||
else | ||
raise AnyCache::UnsupportedCacheDriverError | ||
end | ||
end | ||
# rubocop:enable Metrics/LineLength | ||
end | ||
end |
Oops, something went wrong.