collectionspace-refcache 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.git-blame-ignore-revs +2 -0
- data/.github/workflows/ci.yml +30 -0
- data/.github/workflows/publish.yml +42 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +4 -0
- data/.ruby-version +1 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +88 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/rspec +29 -0
- data/bin/setup +8 -0
- data/collectionspace-refcache.gemspec +37 -0
- data/doc/REFCACHE.md +31 -0
- data/lib/collectionspace/refcache/backend/redis.rb +51 -0
- data/lib/collectionspace/refcache/backend/zache.rb +49 -0
- data/lib/collectionspace/refcache/backend.rb +11 -0
- data/lib/collectionspace/refcache/refcache.rb +217 -0
- data/lib/collectionspace/refcache/version.rb +9 -0
- data/lib/collectionspace/refcache.rb +9 -0
- metadata +194 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c38f8c09590b06bacca02630a58d0470ab97807e0da4a0004f96e1f37d24c826
|
4
|
+
data.tar.gz: b4453a9b856d0ac400bacf394b0455252558d3ef05e7b44586d1014711bc5cc7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 969957ef1d7b7641bbbe6a27ab64ce52f903628fd75be2bbc4c35e8fd3f1496bbdc73657e107b2ff4f408e6303f36c658e2efd25d7fac668e4279febeda5e13b
|
7
|
+
data.tar.gz: 1d8b175e29860eba192c2ce7c2bfb3ec401b21d1c2bc37e3cff89354612e8bc750531fe6f00f0c14980cccf8ef93fee48141c1152078e9c4644a0791b7c20c97
|
@@ -0,0 +1,30 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [pull_request]
|
3
|
+
|
4
|
+
jobs:
|
5
|
+
tests:
|
6
|
+
name: Tests
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby-version: ['3.2', '3.1.3', '3.0.5', '2.7.4']
|
11
|
+
steps:
|
12
|
+
- name: Checkout code
|
13
|
+
uses: actions/checkout@v3
|
14
|
+
|
15
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
16
|
+
uses: ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
bundler-cache: true
|
19
|
+
ruby-version: ${{ matrix.ruby-version }}
|
20
|
+
|
21
|
+
- name: Install dependencies
|
22
|
+
run: bundle install
|
23
|
+
|
24
|
+
- name: Lint
|
25
|
+
run: |
|
26
|
+
bundle exec standardrb
|
27
|
+
|
28
|
+
- name: Run tests
|
29
|
+
run: |
|
30
|
+
bundle exec rake
|
@@ -0,0 +1,42 @@
|
|
1
|
+
name: Publish Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
- master
|
8
|
+
jobs:
|
9
|
+
publish:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
permissions:
|
12
|
+
contents: write
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v3
|
16
|
+
|
17
|
+
- name: Setup Ruby and install gems
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
bundler-cache: true
|
21
|
+
ruby-version: 3.2
|
22
|
+
rubygems: latest
|
23
|
+
|
24
|
+
- name: Release Gem
|
25
|
+
run: |
|
26
|
+
VERSION=$(bundle exec rake version)
|
27
|
+
GEM_VERSION=$(gem list --exact --remote $GEM_NAME)
|
28
|
+
|
29
|
+
# Publish to RubyGems.org
|
30
|
+
if [ "${GEM_VERSION}" != "$GEM_NAME (${VERSION})" ]; then
|
31
|
+
gem build $GEM_NAME.gemspec
|
32
|
+
gem push "$GEM_NAME-${VERSION}.gem"
|
33
|
+
fi
|
34
|
+
|
35
|
+
# Create a release tag
|
36
|
+
if ! git ls-remote --tags --exit-code origin v${VERSION}; then
|
37
|
+
git tag v${VERSION}
|
38
|
+
git push --tags
|
39
|
+
fi
|
40
|
+
env:
|
41
|
+
GEM_HOST_API_KEY: "${{ secrets.RUBYGEMS_AUTH_TOKEN }}"
|
42
|
+
GEM_NAME: collectionspace-refcache
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.1
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
collectionspace-refcache (1.0.0)
|
5
|
+
redis (~> 4.2.1)
|
6
|
+
zache (~> 0.12.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.2)
|
12
|
+
coderay (1.1.3)
|
13
|
+
diff-lcs (1.5.0)
|
14
|
+
docile (1.4.0)
|
15
|
+
json (2.6.3)
|
16
|
+
language_server-protocol (3.17.0.3)
|
17
|
+
method_source (1.0.0)
|
18
|
+
mock_redis (0.29.0)
|
19
|
+
ruby2_keywords
|
20
|
+
parallel (1.22.1)
|
21
|
+
parser (3.2.1.1)
|
22
|
+
ast (~> 2.4.1)
|
23
|
+
pry (0.14.2)
|
24
|
+
coderay (~> 1.1)
|
25
|
+
method_source (~> 1.0)
|
26
|
+
rainbow (3.1.1)
|
27
|
+
rake (13.0.6)
|
28
|
+
redis (4.2.5)
|
29
|
+
regexp_parser (2.7.0)
|
30
|
+
rexml (3.2.5)
|
31
|
+
rspec (3.12.0)
|
32
|
+
rspec-core (~> 3.12.0)
|
33
|
+
rspec-expectations (~> 3.12.0)
|
34
|
+
rspec-mocks (~> 3.12.0)
|
35
|
+
rspec-core (3.12.1)
|
36
|
+
rspec-support (~> 3.12.0)
|
37
|
+
rspec-expectations (3.12.2)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.12.0)
|
40
|
+
rspec-mocks (3.12.3)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.12.0)
|
43
|
+
rspec-support (3.12.0)
|
44
|
+
rubocop (1.44.1)
|
45
|
+
json (~> 2.3)
|
46
|
+
parallel (~> 1.10)
|
47
|
+
parser (>= 3.2.0.0)
|
48
|
+
rainbow (>= 2.2.2, < 4.0)
|
49
|
+
regexp_parser (>= 1.8, < 3.0)
|
50
|
+
rexml (>= 3.2.5, < 4.0)
|
51
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
52
|
+
ruby-progressbar (~> 1.7)
|
53
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
54
|
+
rubocop-ast (1.27.0)
|
55
|
+
parser (>= 3.2.1.0)
|
56
|
+
rubocop-performance (1.15.2)
|
57
|
+
rubocop (>= 1.7.0, < 2.0)
|
58
|
+
rubocop-ast (>= 0.4.0)
|
59
|
+
ruby-progressbar (1.13.0)
|
60
|
+
ruby2_keywords (0.0.5)
|
61
|
+
simplecov (0.22.0)
|
62
|
+
docile (~> 1.1)
|
63
|
+
simplecov-html (~> 0.11)
|
64
|
+
simplecov_json_formatter (~> 0.1)
|
65
|
+
simplecov-html (0.12.3)
|
66
|
+
simplecov_json_formatter (0.1.4)
|
67
|
+
standard (1.24.3)
|
68
|
+
language_server-protocol (~> 3.17.0.2)
|
69
|
+
rubocop (= 1.44.1)
|
70
|
+
rubocop-performance (= 1.15.2)
|
71
|
+
unicode-display_width (2.4.2)
|
72
|
+
zache (0.12.0)
|
73
|
+
|
74
|
+
PLATFORMS
|
75
|
+
ruby
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
collectionspace-refcache!
|
79
|
+
mock_redis (~> 0.29.0)
|
80
|
+
pry
|
81
|
+
rake (~> 13.0)
|
82
|
+
rspec
|
83
|
+
rubocop
|
84
|
+
simplecov (~> 0.21)
|
85
|
+
standard
|
86
|
+
|
87
|
+
BUNDLED WITH
|
88
|
+
2.4.8
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Mark Cooper
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# CollectionSpace RefCache
|
2
|
+
|
3
|
+
A caching system for CollectionSpace refnames.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile (replace `$VERSION` with an available tag):
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'collectionspace-refcache', tag: $VERSION, git: 'https://github.com/collectionspace/collectionspace-refcache.git'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Follow the [examples](doc/REFCACHE.md)!
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/collectionspace/collectionspace-refcache.
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'collectionspace/refcache'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/collectionspace/refcache/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "collectionspace-refcache"
|
7
|
+
spec.version = CollectionSpace::RefCache::VERSION
|
8
|
+
spec.authors = ["Mark Cooper"]
|
9
|
+
spec.email = ["mark.c.cooper@outlook.com"]
|
10
|
+
|
11
|
+
spec.summary = "CollectionSpace RefCache."
|
12
|
+
spec.description = "A caching system for CollectionSpace refnames."
|
13
|
+
spec.homepage = "https://github.org/collectionspace/collectionspace-refcache"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.7.4"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_dependency("redis", "~> 4.2.1")
|
28
|
+
spec.add_dependency("zache", "~> 0.12.0")
|
29
|
+
|
30
|
+
spec.add_development_dependency("mock_redis", "~> 0.29.0")
|
31
|
+
spec.add_development_dependency("pry")
|
32
|
+
spec.add_development_dependency("rake", "~> 13.0")
|
33
|
+
spec.add_development_dependency("rspec")
|
34
|
+
spec.add_development_dependency("rubocop")
|
35
|
+
spec.add_development_dependency("simplecov", "~> 0.21")
|
36
|
+
spec.add_development_dependency("standard")
|
37
|
+
end
|
data/doc/REFCACHE.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# RefCache
|
2
|
+
|
3
|
+
Setup and usage:
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
cache_config = {
|
7
|
+
# redis: 'redis://localhost:6379/1', # optional, if omitted use in memory cache (Zache)
|
8
|
+
domain: 'core.collectionspace.org',
|
9
|
+
error_if_not_found: false, # raise error if key cannot be retrieved (default false)
|
10
|
+
lifetime: 5 * 60, # cache expiry in seconds (default is 5 minutes)
|
11
|
+
}
|
12
|
+
cache = CollectionSpace::RefCache.new(config: cache_config)
|
13
|
+
cache.get('placeauthorities', 'place', 'Death Valley') # $refname or error / nil if not found
|
14
|
+
cache.exists?('placeauthorities', 'place', 'Death Valley') # check for key
|
15
|
+
|
16
|
+
# example for vocabs
|
17
|
+
cache.get('vocabularies', 'languages', 'English') # $refname or error / nil if not found
|
18
|
+
cache.exists?('vocabularies', 'languages', 'English') # check for key
|
19
|
+
```
|
20
|
+
|
21
|
+
The cache can be pre-populated:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
items = [
|
25
|
+
['placeauthorities', 'place', 'Mars Colony', '$refname']
|
26
|
+
].each do |item|
|
27
|
+
cache.put(*item)
|
28
|
+
end
|
29
|
+
cache.exists?('placeauthorities', 'place', 'Mars Colony') # true
|
30
|
+
cache.get('placeauthorities', 'place', 'Mars Colony') # '$refname'
|
31
|
+
```
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "redis"
|
4
|
+
|
5
|
+
module CollectionSpace
|
6
|
+
class RefCache
|
7
|
+
module Backend
|
8
|
+
class Redis
|
9
|
+
def initialize(url)
|
10
|
+
# https://devcenter.heroku.com/articles/heroku-redis#connecting-in-rails
|
11
|
+
@c = ::Redis.new(url: url, ssl_params: {verify_mode: OpenSSL::SSL::VERIFY_NONE})
|
12
|
+
end
|
13
|
+
|
14
|
+
def clean
|
15
|
+
# blank method; Redis handles removal of expired keys automagically, as per
|
16
|
+
# https://redis.io/commands/expire
|
17
|
+
end
|
18
|
+
|
19
|
+
def connected?
|
20
|
+
@c.ping
|
21
|
+
rescue
|
22
|
+
false
|
23
|
+
end
|
24
|
+
|
25
|
+
def exists?(key)
|
26
|
+
@c.exists?(key)
|
27
|
+
end
|
28
|
+
|
29
|
+
def flush
|
30
|
+
@c.flushdb
|
31
|
+
end
|
32
|
+
|
33
|
+
def get(key)
|
34
|
+
@c.get(key)
|
35
|
+
end
|
36
|
+
|
37
|
+
def put(key, value, lifetime: nil)
|
38
|
+
@c.set(key, value, ex: lifetime)
|
39
|
+
end
|
40
|
+
|
41
|
+
def remove(key)
|
42
|
+
@c.del(key)
|
43
|
+
end
|
44
|
+
|
45
|
+
def size
|
46
|
+
@c.dbsize
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "zache"
|
4
|
+
|
5
|
+
module CollectionSpace
|
6
|
+
class RefCache
|
7
|
+
module Backend
|
8
|
+
class Zache
|
9
|
+
def initialize
|
10
|
+
@c = ::Zache.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def clean
|
14
|
+
@c.remove_by { |key| @c.expired?(key) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def connected?
|
18
|
+
"PONG" # cute, matches redis response
|
19
|
+
end
|
20
|
+
|
21
|
+
def exists?(key)
|
22
|
+
@c.exists?(key)
|
23
|
+
end
|
24
|
+
|
25
|
+
def flush
|
26
|
+
@c.remove_all
|
27
|
+
end
|
28
|
+
|
29
|
+
def get(key)
|
30
|
+
@c.get(key)
|
31
|
+
rescue
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def put(key, value, lifetime: nil)
|
36
|
+
@c.put(key, value, lifetime: lifetime)
|
37
|
+
end
|
38
|
+
|
39
|
+
def remove(key)
|
40
|
+
@c.remove(key)
|
41
|
+
end
|
42
|
+
|
43
|
+
def size
|
44
|
+
@c.size
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "digest"
|
4
|
+
|
5
|
+
module CollectionSpace
|
6
|
+
class RefCache
|
7
|
+
class NotFoundError < StandardError; end
|
8
|
+
|
9
|
+
attr_reader :config, :domain
|
10
|
+
|
11
|
+
def initialize(config: {})
|
12
|
+
@config = config
|
13
|
+
@cache = backend(config.fetch(:redis, nil))
|
14
|
+
@domain = config.fetch(:domain)
|
15
|
+
@error_if_not_found = config.fetch(:error_if_not_found, false)
|
16
|
+
@lifetime = config.fetch(:lifetime, 5 * 60)
|
17
|
+
end
|
18
|
+
|
19
|
+
#####
|
20
|
+
# General cache operations
|
21
|
+
#####
|
22
|
+
|
23
|
+
# deletes expired keys (run using cron etc.)
|
24
|
+
def clean
|
25
|
+
@cache.clean
|
26
|
+
end
|
27
|
+
|
28
|
+
def connected?
|
29
|
+
@cache.connected?
|
30
|
+
end
|
31
|
+
|
32
|
+
# delete all keys from the cache
|
33
|
+
#
|
34
|
+
# If Redis backend, only deletes keys from active database
|
35
|
+
def flush
|
36
|
+
@cache.flush
|
37
|
+
end
|
38
|
+
|
39
|
+
def size
|
40
|
+
@cache.size
|
41
|
+
end
|
42
|
+
|
43
|
+
#####
|
44
|
+
# Default methods (assumes authority terms)
|
45
|
+
# cache.exists?('placeauthorities', 'place', 'Death Valley')
|
46
|
+
def exists?(type, subtype, value)
|
47
|
+
generic_exists?(term_key(type, subtype, value))
|
48
|
+
end
|
49
|
+
|
50
|
+
# cache.put('placeauthorities', 'place', 'The Moon', $refname)
|
51
|
+
# rubocop:disable Metrics/ParameterLists
|
52
|
+
def put(type, subtype, value, to_cache)
|
53
|
+
put_generic(term_key(type, subtype, value), to_cache)
|
54
|
+
end
|
55
|
+
# rubocop:enable Metrics/ParameterLists
|
56
|
+
|
57
|
+
# cache.get('placeauthorities', 'place', 'The Moon')
|
58
|
+
# cache.get('vocabularies', 'languages', 'English')
|
59
|
+
def get(type, subtype, value)
|
60
|
+
get_generic(term_key(type, subtype, value))
|
61
|
+
end
|
62
|
+
|
63
|
+
def remove(type, subtype, value)
|
64
|
+
remove_generic(term_key(type, subtype, value))
|
65
|
+
end
|
66
|
+
|
67
|
+
#####
|
68
|
+
# object caching
|
69
|
+
#####
|
70
|
+
def put_object(id, to_cache)
|
71
|
+
put_generic(object_key(id), to_cache)
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_object(id)
|
75
|
+
get_generic(object_key(id))
|
76
|
+
end
|
77
|
+
|
78
|
+
def remove_object(id)
|
79
|
+
remove_generic(object_key(id))
|
80
|
+
end
|
81
|
+
|
82
|
+
def object_exists?(id)
|
83
|
+
generic_exists?(object_key(id))
|
84
|
+
end
|
85
|
+
|
86
|
+
#####
|
87
|
+
# procedure caching
|
88
|
+
#####
|
89
|
+
def put_procedure(type, id, to_cache)
|
90
|
+
put_generic(procedure_key(type, id), to_cache)
|
91
|
+
end
|
92
|
+
|
93
|
+
def get_procedure(type, id)
|
94
|
+
get_generic(procedure_key(type, id))
|
95
|
+
end
|
96
|
+
|
97
|
+
def remove_procedure(type, id)
|
98
|
+
remove_generic(procedure_key(type, id))
|
99
|
+
end
|
100
|
+
|
101
|
+
def procedure_exists?(type, id)
|
102
|
+
generic_exists?(procedure_key(type, id))
|
103
|
+
end
|
104
|
+
|
105
|
+
#####
|
106
|
+
# authority term caching
|
107
|
+
#####
|
108
|
+
def auth_term_exists?(type, subtype, term)
|
109
|
+
generic_exists?(term_key(type, subtype, term))
|
110
|
+
end
|
111
|
+
|
112
|
+
# rubocop:disable Metrics/ParameterLists
|
113
|
+
def put_auth_term(type, subtype, term, to_cache)
|
114
|
+
put_generic(term_key(type, subtype, term), to_cache)
|
115
|
+
end
|
116
|
+
# rubocop:enable Metrics/ParameterLists
|
117
|
+
|
118
|
+
def get_auth_term(type, subtype, term)
|
119
|
+
get_generic(term_key(type, subtype, term))
|
120
|
+
end
|
121
|
+
|
122
|
+
def remove_auth_term(type, subtype, term)
|
123
|
+
remove_generic(term_key(type, subtype, term))
|
124
|
+
end
|
125
|
+
|
126
|
+
#####
|
127
|
+
# relation caching
|
128
|
+
#####
|
129
|
+
def relation_exists?(reltype, subjectcsid, objectcsid)
|
130
|
+
generic_exists?(term_key(reltype, subjectcsid, objectcsid))
|
131
|
+
end
|
132
|
+
|
133
|
+
# rubocop:disable Metrics/ParameterLists
|
134
|
+
def put_relation(reltype, subjectcsid, objectcsid, to_cache)
|
135
|
+
put_generic(term_key(reltype, subjectcsid, objectcsid), to_cache)
|
136
|
+
end
|
137
|
+
# rubocop:enable Metrics/ParameterLists
|
138
|
+
|
139
|
+
def get_relation(reltype, subjectcsid, objectcsid)
|
140
|
+
get_generic(term_key(reltype, subjectcsid, objectcsid))
|
141
|
+
end
|
142
|
+
|
143
|
+
def remove_relation(reltype, subjectcsid, objectcsid)
|
144
|
+
remove_generic(term_key(reltype, subjectcsid, objectcsid))
|
145
|
+
end
|
146
|
+
|
147
|
+
#####
|
148
|
+
# vocabulary term caching
|
149
|
+
#####
|
150
|
+
def vocab_term_exists?(vocab, term)
|
151
|
+
generic_exists?(vocab_term_key(vocab, term))
|
152
|
+
end
|
153
|
+
|
154
|
+
# rubocop:disable Metrics/ParameterLists
|
155
|
+
def put_vocab_term(vocab, term, to_cache)
|
156
|
+
put_generic(vocab_term_key(vocab, term), to_cache)
|
157
|
+
end
|
158
|
+
# rubocop:enable Metrics/ParameterLists
|
159
|
+
|
160
|
+
def get_vocab_term(vocab, term)
|
161
|
+
get_generic(vocab_term_key(vocab, term))
|
162
|
+
end
|
163
|
+
|
164
|
+
def remove_vocab_term(vocab, term)
|
165
|
+
remove_generic(vocab_term_key(vocab, term))
|
166
|
+
end
|
167
|
+
|
168
|
+
private
|
169
|
+
|
170
|
+
def put_generic(key, to_cache)
|
171
|
+
@cache.put(key, to_cache, lifetime: @lifetime)
|
172
|
+
end
|
173
|
+
|
174
|
+
def get_generic(key)
|
175
|
+
cached_value = @cache.get(key)
|
176
|
+
raise(NotFoundError) if @error_if_not_found && !cached_value
|
177
|
+
|
178
|
+
cached_value
|
179
|
+
end
|
180
|
+
|
181
|
+
def remove_generic(key)
|
182
|
+
@cache.remove(key)
|
183
|
+
end
|
184
|
+
|
185
|
+
def generic_exists?(key)
|
186
|
+
@cache.exists?(key)
|
187
|
+
end
|
188
|
+
|
189
|
+
def backend(connection)
|
190
|
+
connection ? Backend::Redis.new(connection) : Backend::Zache.new
|
191
|
+
end
|
192
|
+
|
193
|
+
def generate_key(parts = [])
|
194
|
+
Digest::SHA2.hexdigest(parts.dup.append(domain).join).prepend("refcache::")
|
195
|
+
end
|
196
|
+
|
197
|
+
def object_key(id)
|
198
|
+
generate_key(["collectionobjects", id])
|
199
|
+
end
|
200
|
+
|
201
|
+
def procedure_key(type, id)
|
202
|
+
generate_key([type, id])
|
203
|
+
end
|
204
|
+
|
205
|
+
def relation_key(reltype, subjectcsid, objectcsid)
|
206
|
+
generate_key([reltype, subjectcsid, objectcsid])
|
207
|
+
end
|
208
|
+
|
209
|
+
def term_key(type, subtype, term)
|
210
|
+
generate_key([type, subtype, term])
|
211
|
+
end
|
212
|
+
|
213
|
+
def vocab_term_key(vocab, term)
|
214
|
+
generate_key(["vocabularies", vocab, term])
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
metadata
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: collectionspace-refcache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Cooper
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-03-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: zache
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.12.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.12.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mock_redis
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.29.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.29.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '13.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '13.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.21'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.21'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: standard
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: A caching system for CollectionSpace refnames.
|
140
|
+
email:
|
141
|
+
- mark.c.cooper@outlook.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".git-blame-ignore-revs"
|
147
|
+
- ".github/workflows/ci.yml"
|
148
|
+
- ".github/workflows/publish.yml"
|
149
|
+
- ".gitignore"
|
150
|
+
- ".rspec"
|
151
|
+
- ".rubocop.yml"
|
152
|
+
- ".ruby-version"
|
153
|
+
- Gemfile
|
154
|
+
- Gemfile.lock
|
155
|
+
- LICENSE.txt
|
156
|
+
- README.md
|
157
|
+
- Rakefile
|
158
|
+
- bin/console
|
159
|
+
- bin/rspec
|
160
|
+
- bin/setup
|
161
|
+
- collectionspace-refcache.gemspec
|
162
|
+
- doc/REFCACHE.md
|
163
|
+
- lib/collectionspace/refcache.rb
|
164
|
+
- lib/collectionspace/refcache/backend.rb
|
165
|
+
- lib/collectionspace/refcache/backend/redis.rb
|
166
|
+
- lib/collectionspace/refcache/backend/zache.rb
|
167
|
+
- lib/collectionspace/refcache/refcache.rb
|
168
|
+
- lib/collectionspace/refcache/version.rb
|
169
|
+
homepage: https://github.org/collectionspace/collectionspace-refcache
|
170
|
+
licenses:
|
171
|
+
- MIT
|
172
|
+
metadata:
|
173
|
+
homepage_uri: https://github.org/collectionspace/collectionspace-refcache
|
174
|
+
source_code_uri: https://github.org/collectionspace/collectionspace-refcache
|
175
|
+
post_install_message:
|
176
|
+
rdoc_options: []
|
177
|
+
require_paths:
|
178
|
+
- lib
|
179
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: 2.7.4
|
184
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
requirements: []
|
190
|
+
rubygems_version: 3.4.8
|
191
|
+
signing_key:
|
192
|
+
specification_version: 4
|
193
|
+
summary: CollectionSpace RefCache.
|
194
|
+
test_files: []
|