Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.2', '3.1.3', '3.0.5', '2.7.4']
ruby-version: ['4.0']
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.1
4.0.5
152 changes: 103 additions & 49 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,77 +1,92 @@
PATH
remote: .
specs:
collectionspace-refcache (1.0.0)
collectionspace-refcache (1.0.1)
redis (~> 4.2.1)
zache (~> 0.12.0)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
ast (2.4.3)
coderay (1.1.3)
diff-lcs (1.5.0)
docile (1.4.0)
json (2.6.3)
language_server-protocol (3.17.0.3)
method_source (1.0.0)
diff-lcs (1.6.2)
io-console (0.9.4)
json (3.1.0)
language_server-protocol (3.17.0.6)
lint_roller (1.1.0)
method_source (1.1.0)
mock_redis (0.29.0)
ruby2_keywords
parallel (1.22.1)
parser (3.2.1.1)
parallel (2.3.0)
parser (3.3.13.0)
ast (~> 2.4.1)
pry (0.14.2)
racc
prism (1.9.0)
pry (0.16.1)
coderay (~> 1.1)
method_source (~> 1.0)
reline (>= 0.6.0)
racc (1.8.1)
rainbow (3.1.1)
rake (13.0.6)
rake (13.4.2)
redis (4.2.5)
regexp_parser (2.7.0)
rexml (3.3.9)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.1)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.2)
regexp_parser (2.13.1)
reline (0.7.0)
io-console (~> 0.5)
rspec (3.13.2)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.6)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.3)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.8)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.0)
rubocop (1.44.1)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.2.0.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.7)
rubocop (1.91.0)
json (>= 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (>= 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.24.1, < 2.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.49.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.27.0)
parser (>= 3.2.1.0)
rubocop-performance (1.15.2)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.50.0)
parser (>= 3.3.7.2)
prism (~> 1.7)
rubocop-performance (1.26.1)
lint_roller (~> 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.47.1, < 2.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
standard (1.24.3)
simplecov (1.3.2)
standard (1.57.0)
language_server-protocol (~> 3.17.0.2)
rubocop (= 1.44.1)
rubocop-performance (= 1.15.2)
unicode-display_width (2.4.2)
lint_roller (~> 1.0)
rubocop (~> 1.91.0)
standard-custom (~> 1.0.0)
standard-performance (~> 1.8)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.9.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.26.0)
unicode-display_width (3.3.0)
unicode-emoji (~> 4.3)
unicode-emoji (4.3.0)
zache (0.12.0)

PLATFORMS
arm64-darwin-25
ruby

DEPENDENCIES
Expand All @@ -81,8 +96,47 @@ DEPENDENCIES
rake (~> 13.0)
rspec
rubocop
simplecov (~> 0.21)
simplecov
standard

CHECKSUMS
ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
coderay (1.1.3) sha256=dc530018a4684512f8f38143cd2a096c9f02a1fc2459edcfe534787a7fc77d4b
collectionspace-refcache (1.0.1)
diff-lcs (1.6.2) sha256=9ae0d2cba7d4df3075fe8cd8602a8604993efc0dfa934cff568969efb1909962
io-console (0.9.4) sha256=a403304f32928ee85e56d457b4612ca43f2703b561a3258844992bd24085fbb1
json (3.1.0) sha256=3ce7ccf8fde58960177a3a756c31f292a4c1e1dedee884547096a5b0604e3bd8
language_server-protocol (3.17.0.6) sha256=5ef2c0c138f8267e1bc631d3328347d354f96724b0af22f2c79516120443b7f0
lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
method_source (1.1.0) sha256=181301c9c45b731b4769bc81e8860e72f9161ad7d66dd99103c9ab84f560f5c5
mock_redis (0.29.0) sha256=296956fff24a8bf10d771e4f1a54913161de480b879f53f7ae5030aa323c5282
parallel (2.3.0) sha256=f75a3e904101ce6a1ccb6b8dc800cbafd42166d83330192438dcf29395167a6f
parser (3.3.13.0) sha256=e02f9b63c2fe05b0c68f692ba4df89b3cb113b663964f75d988fbebfd6c3deca
prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85
pry (0.16.1) sha256=d92d82c86e7f2dc34beec6d2892d5cf5ea517eea22eed3ceabb38ee62a98accc
racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f
rainbow (3.1.1) sha256=039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a
rake (13.4.2) sha256=cb825b2bd5f1f8e91ca37bddb4b9aaf345551b4731da62949be002fa89283701
redis (4.2.5) sha256=88a85e4a379b8fdfdc76518dd4fd5daa34464735785ef4f6929924004dd6a297
regexp_parser (2.13.1) sha256=5aedb6b7c35688f51e86eef17a15374dfd287c83f4ca644b2c5f3ec50a33b44b
reline (0.7.0) sha256=5b012d8e55dbf9d450f12bde2cf7d15ff546ae80b3f8f3b30e570d431815583d
rspec (3.13.2) sha256=206284a08ad798e61f86d7ca3e376718d52c0bc944626b2349266f239f820587
rspec-core (3.13.6) sha256=a8823c6411667b60a8bca135364351dda34cd55e44ff94c4be4633b37d828b2d
rspec-expectations (3.13.5) sha256=33a4d3a1d95060aea4c94e9f237030a8f9eae5615e9bd85718fe3a09e4b58836
rspec-mocks (3.13.8) sha256=086ad3d3d17533f4237643de0b5c42f04b66348c28bf6b9c2d3f4a3b01af1d47
rspec-support (3.13.7) sha256=0640e5570872aafefd79867901deeeeb40b0c9875a36b983d85f54fb7381c47c
rubocop (1.91.0) sha256=9c82b7bf391c5d7e3798c5b9996e22a1fe3bd7468e351dfdeb96140c058296d0
rubocop-ast (1.50.0) sha256=b9ca88300da0803ee222ad20cdb30494c0a784eed06fdc35d254b06d662788db
rubocop-performance (1.26.1) sha256=cd19b936ff196df85829d264b522fd4f98b6c89ad271fa52744a8c11b8f71834
ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
ruby2_keywords (0.0.5) sha256=ffd13740c573b7301cf7a2e61fc857b2a8e3d3aff32545d6f8300d8bae10e3ef
simplecov (1.3.2) sha256=2a22ec1759f1b8db60881a2e038758956fc69ef93ed669be0bde0678de6d0e85
standard (1.57.0) sha256=4a65ea92421fbaf77fb54da91e16093cf79b335b8f62c35aaa3dd714c8592858
standard-custom (1.0.2) sha256=424adc84179a074f1a2a309bb9cf7cd6bfdb2b6541f20c6bf9436c0ba22a652b
standard-performance (1.9.0) sha256=49483d31be448292951d80e5e67cdcb576c2502103c7b40aec6f1b6e9c88e3f2
unicode-display_width (3.3.0) sha256=4b7aa66a4b11db50f6f7e98411215cd0dd10eaecb665d36eec5bcacb3fa0b613
unicode-emoji (4.3.0) sha256=11c02fa73290378c066bb0562cd4c87d8e1b706fbbe0059ca12746a4244de8ce
zache (0.12.0) sha256=6a3bccae54ca88fa0b0afa9debdbcb30c3f3b470d8763844c10a9fa62b02bce7

BUNDLED WITH
2.4.8
4.0.10
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CollectionSpace RefCache
# CollectionSpace Refcache

A caching system for CollectionSpace refnames.

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ RSpec::Core::RakeTask.new(:spec)
task default: :spec

task :version do
puts CollectionSpace::RefCache::VERSION
puts CollectionSpace::Refcache::VERSION
end
8 changes: 4 additions & 4 deletions collectionspace-refcache.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ require_relative "lib/collectionspace/refcache/version"

Gem::Specification.new do |spec|
spec.name = "collectionspace-refcache"
spec.version = CollectionSpace::RefCache::VERSION
spec.version = CollectionSpace::Refcache::VERSION
spec.authors = ["Mark Cooper"]
spec.email = ["mark.c.cooper@outlook.com"]

spec.summary = "CollectionSpace RefCache."
spec.summary = "CollectionSpace Refcache."
spec.description = "A caching system for CollectionSpace refnames."
spec.homepage = "https://github.org/collectionspace/collectionspace-refcache"
spec.license = "MIT"
spec.required_ruby_version = ">= 2.7.4"
spec.required_ruby_version = ">= 4.0.5"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = spec.homepage
Expand All @@ -32,6 +32,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency("rake", "~> 13.0")
spec.add_development_dependency("rspec")
spec.add_development_dependency("rubocop")
spec.add_development_dependency("simplecov", "~> 0.21")
spec.add_development_dependency("simplecov")
spec.add_development_dependency("standard")
end
9 changes: 6 additions & 3 deletions doc/REFCACHE.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# RefCache
# Refcache

Setup and usage:

```ruby
# In-memory cache (Zache) will be used as backend if neither :redis nor :store are included
# in config
cache_config = {
# redis: 'redis://localhost:6379/1', # optional, if omitted use in memory cache (Zache)
# redis: 'redis://localhost:6379/1', # optional
# store: ActiveSupport::Cache::Store or SolidCache::Store object, # optional
domain: 'core.collectionspace.org',
error_if_not_found: false, # raise error if key cannot be retrieved (default false)
lifetime: 5 * 60, # cache expiry in seconds (default is 5 minutes)
}
cache = CollectionSpace::RefCache.new(config: cache_config)
cache = CollectionSpace::Refcache.new(config: cache_config)
cache.get('placeauthorities', 'place', 'Death Valley') # $refname or error / nil if not found
cache.exists?('placeauthorities', 'place', 'Death Valley') # check for key

Expand Down
3 changes: 2 additions & 1 deletion lib/collectionspace/refcache/backend.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# frozen_string_literal: true

require_relative "backend/activesupport_cache_store"
require_relative "backend/redis"
require_relative "backend/zache"

module CollectionSpace
class RefCache
class Refcache
module Backend
end
end
Expand Down
57 changes: 57 additions & 0 deletions lib/collectionspace/refcache/backend/activesupport_cache_store.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# frozen_string_literal: true

module CollectionSpace
class Refcache
module Backend
class ActivesupportCacheStore
# @param store [ActiveSupport::Cache::Store] or other store conforming
# to its abstract interface (e.g. SolidCache::Store)
def initialize(store)
@c = store
end

def clean
return nil unless @c.respond_to?(:clean)

@c.clean
end

def connected?
"PONG" # cute, matches redis response
end

def exists?(key)
@c.exist?(key)
end

def flush
return nil unless @c.respond_to?(:clear)

@c.clear
end

def get(key)
@c.read(key)
end

def put(key, value, lifetime: nil)
if lifetime
@c.write(key, value, expires_in: lifetime)
else
@c.write(key, value)
end
end

def remove(key)
@c.delete(key)
end

def size
return nil unless @c.respond_to?(:stats)

@c.stats.dig(:connection_stats, :cache, :entries)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/collectionspace/refcache/backend/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "redis"

module CollectionSpace
class RefCache
class Refcache
module Backend
class Redis
def initialize(url)
Expand Down
2 changes: 1 addition & 1 deletion lib/collectionspace/refcache/backend/zache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "zache"

module CollectionSpace
class RefCache
class Refcache
module Backend
class Zache
def initialize
Expand Down
14 changes: 10 additions & 4 deletions lib/collectionspace/refcache/refcache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
require "digest"

module CollectionSpace
class RefCache
class Refcache
class NotFoundError < StandardError; end

attr_reader :config, :domain

def initialize(config: {})
@config = config
@cache = backend(config.fetch(:redis, nil))
@cache = set_backend(config)
@domain = config.fetch(:domain)
@error_if_not_found = config.fetch(:error_if_not_found, false)
@lifetime = config.fetch(:lifetime, 5 * 60)
Expand Down Expand Up @@ -190,8 +190,14 @@ def generic_exists?(key)
@cache.exists?(key)
end

def backend(connection)
connection ? Backend::Redis.new(connection) : Backend::Zache.new
def set_backend(config)
if config.key?(:redis)
Backend::Redis.new(config[:redis])
elsif config.key?(:store)
Backend::ActivesupportCacheStore.new(config[:store])
else
Backend::Zache.new
end
end

def generate_key(parts = [])
Expand Down
4 changes: 2 additions & 2 deletions lib/collectionspace/refcache/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

module CollectionSpace
# rubocop:disable Style/StaticClass
class RefCache
VERSION = "1.0.0"
class Refcache
VERSION = "1.0.1"
end
# rubocop:enable Style/StaticClass
end
Loading
Loading