zache 0.13.2 → 0.14.0
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 +4 -4
- data/.0pdd.yml +2 -21
- data/.github/workflows/actionlint.yml +5 -23
- data/.github/workflows/codecov.yml +11 -26
- data/.github/workflows/copyrights.yml +6 -23
- data/.github/workflows/license.yml +5 -22
- data/.github/workflows/markdown-lint.yml +5 -22
- data/.github/workflows/pdd.yml +6 -23
- data/.github/workflows/rake.yml +8 -26
- data/.github/workflows/reuse.yml +19 -0
- data/.github/workflows/xcop.yml +5 -22
- data/.github/workflows/yamllint.yml +5 -22
- data/.gitignore +6 -2
- data/.rubocop.yml +20 -28
- data/.rultor.yml +5 -22
- data/Gemfile +16 -27
- data/Gemfile.lock +78 -40
- data/LICENSE.txt +1 -1
- data/LICENSES/MIT.txt +21 -0
- data/README.md +45 -19
- data/REUSE.toml +31 -0
- data/Rakefile +19 -34
- data/lib/zache.rb +118 -33
- data/logo.svg +1 -1
- data/test/test__helper.rb +24 -21
- data/test/test_zache.rb +85 -84
- data/zache.gemspec +5 -24
- metadata +7 -7
data/Gemfile.lock
CHANGED
@@ -6,72 +6,110 @@ PATH
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
9
|
+
ansi (1.5.0)
|
10
|
+
ast (2.4.3)
|
10
11
|
backtrace (0.4.0)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
builder (3.3.0)
|
13
|
+
concurrent-ruby (1.3.5)
|
14
|
+
docile (1.4.1)
|
15
|
+
elapsed (0.0.1)
|
16
|
+
loog (> 0)
|
17
|
+
tago (> 0)
|
18
|
+
json (2.10.2)
|
19
|
+
language_server-protocol (3.17.0.4)
|
20
|
+
lint_roller (1.1.0)
|
21
|
+
loog (0.6.0)
|
22
|
+
minitest (5.25.5)
|
23
|
+
minitest-reporters (1.7.1)
|
24
|
+
ansi
|
25
|
+
builder
|
26
|
+
minitest (>= 5.0)
|
27
|
+
ruby-progressbar
|
28
|
+
os (1.1.4)
|
29
|
+
parallel (1.26.3)
|
30
|
+
parser (3.3.7.4)
|
18
31
|
ast (~> 2.4.1)
|
19
32
|
racc
|
20
|
-
|
21
|
-
|
22
|
-
|
33
|
+
prism (1.4.0)
|
34
|
+
qbash (0.4.0)
|
35
|
+
backtrace (> 0)
|
36
|
+
elapsed (> 0)
|
37
|
+
loog (> 0)
|
38
|
+
tago (> 0)
|
39
|
+
racc (1.8.1)
|
23
40
|
rainbow (3.1.1)
|
24
41
|
rake (13.2.1)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
rexml (3.3.2)
|
29
|
-
strscan
|
30
|
-
rubocop (1.65.0)
|
42
|
+
regexp_parser (2.10.0)
|
43
|
+
rexml (3.4.1)
|
44
|
+
rubocop (1.75.2)
|
31
45
|
json (~> 2.3)
|
32
|
-
language_server-protocol (
|
46
|
+
language_server-protocol (~> 3.17.0.2)
|
47
|
+
lint_roller (~> 1.1.0)
|
33
48
|
parallel (~> 1.10)
|
34
49
|
parser (>= 3.3.0.2)
|
35
50
|
rainbow (>= 2.2.2, < 4.0)
|
36
|
-
regexp_parser (>= 2.
|
37
|
-
|
38
|
-
rubocop-ast (>= 1.31.1, < 2.0)
|
51
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
52
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
39
53
|
ruby-progressbar (~> 1.7)
|
40
|
-
unicode-display_width (>= 2.4.0, <
|
41
|
-
rubocop-ast (1.
|
42
|
-
parser (>= 3.3.
|
43
|
-
|
44
|
-
|
54
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
55
|
+
rubocop-ast (1.44.1)
|
56
|
+
parser (>= 3.3.7.2)
|
57
|
+
prism (~> 1.4)
|
58
|
+
rubocop-minitest (0.38.0)
|
59
|
+
lint_roller (~> 1.1)
|
60
|
+
rubocop (>= 1.75.0, < 2.0)
|
61
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
62
|
+
rubocop-performance (1.25.0)
|
63
|
+
lint_roller (~> 1.1)
|
64
|
+
rubocop (>= 1.75.0, < 2.0)
|
65
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
66
|
+
rubocop-rake (0.7.1)
|
67
|
+
lint_roller (~> 1.1)
|
68
|
+
rubocop (>= 1.72.1)
|
45
69
|
ruby-progressbar (1.13.0)
|
46
70
|
simplecov (0.22.0)
|
47
71
|
docile (~> 1.1)
|
48
72
|
simplecov-html (~> 0.11)
|
49
73
|
simplecov_json_formatter (~> 0.1)
|
50
|
-
simplecov-
|
74
|
+
simplecov-cobertura (2.1.0)
|
75
|
+
rexml
|
76
|
+
simplecov (~> 0.19)
|
77
|
+
simplecov-html (0.13.1)
|
51
78
|
simplecov_json_formatter (0.1.4)
|
52
|
-
|
53
|
-
|
54
|
-
threads (0.4.0)
|
79
|
+
tago (0.1.0)
|
80
|
+
threads (0.4.1)
|
55
81
|
backtrace (~> 0)
|
56
82
|
concurrent-ruby (~> 1.0)
|
57
|
-
unicode-display_width (
|
83
|
+
unicode-display_width (3.1.4)
|
84
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
85
|
+
unicode-emoji (4.0.4)
|
86
|
+
yard (0.9.37)
|
58
87
|
|
59
88
|
PLATFORMS
|
60
89
|
arm64-darwin-22
|
90
|
+
arm64-darwin-23
|
91
|
+
arm64-darwin-24
|
92
|
+
x64-mingw-ucrt
|
61
93
|
x86_64-darwin-20
|
62
94
|
x86_64-darwin-21
|
63
95
|
x86_64-linux
|
64
96
|
|
65
97
|
DEPENDENCIES
|
66
|
-
concurrent-ruby (
|
67
|
-
minitest (
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
98
|
+
concurrent-ruby (~> 1.3)
|
99
|
+
minitest (~> 5.25)
|
100
|
+
minitest-reporters (~> 1.7)
|
101
|
+
os (> 0)
|
102
|
+
qbash (> 0)
|
103
|
+
rake (~> 13.2)
|
104
|
+
rubocop (~> 1.75)
|
105
|
+
rubocop-minitest (> 0)
|
106
|
+
rubocop-performance (> 0)
|
107
|
+
rubocop-rake (> 0)
|
108
|
+
simplecov (~> 0.22)
|
109
|
+
simplecov-cobertura (~> 2.1)
|
110
|
+
threads (~> 0.4)
|
111
|
+
yard (~> 0.9)
|
74
112
|
zache!
|
75
113
|
|
76
114
|
BUNDLED WITH
|
77
|
-
2.5.
|
115
|
+
2.5.16
|
data/LICENSE.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2018-
|
3
|
+
Copyright (c) 2018-2025 Yegor Bugayenko
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/LICENSES/MIT.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018-2025 Yegor Bugayenko
|
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
|
13
|
+
in 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 NON-INFRINGEMENT. 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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# In Memory Cache for Ruby
|
2
2
|
|
3
3
|
[](https://www.elegantobjects.org)
|
4
|
-
[](https://www.rultor.com/p/yegor256/zache)
|
5
5
|
[](https://www.jetbrains.com/ruby/)
|
6
6
|
|
7
7
|
[](https://github.com/yegor256/zache/actions/workflows/rake.yml)
|
8
|
-
[](
|
8
|
+
[](https://badge.fury.io/rb/zache)
|
9
9
|
[](https://codeclimate.com/github/yegor256/zache/maintainability)
|
10
|
-
[](https://rubydoc.info/github/yegor256/zache/master/frames)
|
11
11
|
[](https://github.com/yegor256/zache/blob/master/LICENSE.txt)
|
12
12
|
[](https://codecov.io/github/yegor256/zache?branch=master)
|
13
13
|
[](https://hitsofcode.com/view/github/yegor256/zache)
|
14
14
|
|
15
|
-
|
15
|
+
This is a simple Ruby gem for in-memory caching.
|
16
16
|
Read [this blog post](https://www.yegor256.com/2019/02/05/zache.html)
|
17
|
-
to understand what Zache is for.
|
17
|
+
to understand what Zache is designed for.
|
18
18
|
|
19
19
|
First, install it:
|
20
20
|
|
@@ -22,41 +22,67 @@ First, install it:
|
|
22
22
|
gem install zache
|
23
23
|
```
|
24
24
|
|
25
|
-
Then, use it like this
|
25
|
+
Then, use it like this:
|
26
26
|
|
27
27
|
```ruby
|
28
28
|
require 'zache'
|
29
29
|
zache = Zache.new
|
30
30
|
# Expires in 5 minutes
|
31
|
-
v = zache.get(:count, lifetime: 5 * 60) {
|
31
|
+
v = zache.get(:count, lifetime: 5 * 60) { expensive_calculation() }
|
32
32
|
```
|
33
33
|
|
34
|
+
If you omit the `lifetime` parameter, the key will never expire.
|
35
|
+
|
34
36
|
By default `Zache` is thread-safe. It locks the entire cache on each
|
35
|
-
`get` call. You turn that off by using `sync` argument:
|
37
|
+
`get` call. You can turn that off by using the `sync` argument:
|
36
38
|
|
37
39
|
```ruby
|
38
40
|
zache = Zache.new(sync: false)
|
39
|
-
v = zache.get(:count) {
|
41
|
+
v = zache.get(:count) { expensive_calculation() }
|
40
42
|
```
|
41
43
|
|
42
|
-
You may use "dirty" mode, which will return
|
43
|
-
calculation is
|
44
|
-
expired
|
45
|
-
|
46
|
-
receive
|
47
|
-
|
44
|
+
You may use "dirty" mode, which will return an expired value while
|
45
|
+
calculation is in progress. For example, if you have a value in the cache that's
|
46
|
+
expired, and you call `get` with a long-running block, the thread waits.
|
47
|
+
If another thread calls `get` again, that second thread won't wait, but will
|
48
|
+
receive the expired value from the cache. This is a very convenient mode for situations
|
49
|
+
where absolute data accuracy is less important than performance:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
zache = Zache.new(dirty: true)
|
53
|
+
# Or enable dirty mode for a specific get call
|
54
|
+
value = zache.get(:key, dirty: true) { expensive_calculation() }
|
55
|
+
```
|
48
56
|
|
49
57
|
The entire API is documented
|
50
|
-
[here](https://www.rubydoc.info/github/yegor256/zache/master/Zache)
|
51
|
-
|
58
|
+
[here](https://www.rubydoc.info/github/yegor256/zache/master/Zache).
|
59
|
+
Here are some additional useful methods:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
# Check if a key exists
|
63
|
+
zache.exists?(:key)
|
52
64
|
|
53
|
-
|
65
|
+
# Remove a key
|
66
|
+
zache.remove(:key)
|
67
|
+
|
68
|
+
# Remove all keys
|
69
|
+
zache.remove_all
|
70
|
+
|
71
|
+
# Remove keys that match a condition
|
72
|
+
zache.remove_by { |key| key.to_s.start_with?('temp_') }
|
73
|
+
|
74
|
+
# Clean up expired keys
|
75
|
+
zache.clean
|
76
|
+
|
77
|
+
# Check if cache is empty
|
78
|
+
zache.empty?
|
79
|
+
```
|
54
80
|
|
55
81
|
## How to contribute
|
56
82
|
|
57
83
|
Read
|
58
84
|
[these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
|
59
|
-
Make sure
|
85
|
+
Make sure your build is green before you contribute
|
60
86
|
your pull request. You will need to have
|
61
87
|
[Ruby](https://www.ruby-lang.org/en/) 2.3+ and
|
62
88
|
[Bundler](https://bundler.io/) installed. Then:
|
data/REUSE.toml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025 Yegor Bugayenko
|
2
|
+
# SPDX-License-Identifier: MIT
|
3
|
+
|
4
|
+
version = 1
|
5
|
+
[[annotations]]
|
6
|
+
path = [
|
7
|
+
"**/*.csv",
|
8
|
+
"**/*.jpg",
|
9
|
+
"**/*.json",
|
10
|
+
"**/*.md",
|
11
|
+
"**/*.pdf",
|
12
|
+
"**/*.png",
|
13
|
+
"**/*.svg",
|
14
|
+
"**/*.txt",
|
15
|
+
"**/*.vm",
|
16
|
+
"**/.DS_Store",
|
17
|
+
"**/.gitignore",
|
18
|
+
"**/.pdd",
|
19
|
+
"**/CNAME",
|
20
|
+
"**/Gemfile.lock",
|
21
|
+
".DS_Store",
|
22
|
+
".gitattributes",
|
23
|
+
".gitignore",
|
24
|
+
".pdd",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"README.md",
|
27
|
+
"renovate.json",
|
28
|
+
]
|
29
|
+
precedence = "override"
|
30
|
+
SPDX-FileCopyrightText = "Copyright (c) 2018-2025 Yegor Bugayenko"
|
31
|
+
SPDX-License-Identifier = "MIT"
|
data/Rakefile
CHANGED
@@ -1,25 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018-
|
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 all
|
13
|
-
# 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 THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2018-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
6
|
+
require 'os'
|
7
|
+
require 'qbash'
|
23
8
|
require 'rubygems'
|
24
9
|
require 'rake'
|
25
10
|
require 'rake/clean'
|
@@ -34,7 +19,7 @@ def version
|
|
34
19
|
Gem::Specification.load(Dir['*.gemspec'].first).version
|
35
20
|
end
|
36
21
|
|
37
|
-
task default: %i[clean test rubocop
|
22
|
+
task default: %i[clean test picks rubocop yard]
|
38
23
|
|
39
24
|
require 'rake/testtask'
|
40
25
|
desc 'Run all unit tests'
|
@@ -44,24 +29,24 @@ Rake::TestTask.new(:test) do |test|
|
|
44
29
|
test.verbose = false
|
45
30
|
end
|
46
31
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
32
|
+
desc 'Run them via Ruby, one by one'
|
33
|
+
task :picks do
|
34
|
+
next if OS.windows?
|
35
|
+
%w[test lib].each do |d|
|
36
|
+
Dir["#{d}/**/*.rb"].each do |f|
|
37
|
+
qbash("bundle exec ruby #{Shellwords.escape(f)}", log: $stdout, env: { 'PICKS' => 'yes' })
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
require 'yard'
|
43
|
+
desc 'Build Yard documentation'
|
44
|
+
YARD::Rake::YardocTask.new do |t|
|
45
|
+
t.files = ['lib/**/*.rb']
|
52
46
|
end
|
53
47
|
|
54
48
|
require 'rubocop/rake_task'
|
55
49
|
desc 'Run RuboCop on all directories'
|
56
50
|
RuboCop::RakeTask.new(:rubocop) do |task|
|
57
51
|
task.fail_on_error = true
|
58
|
-
task.requires << 'rubocop-rspec'
|
59
|
-
end
|
60
|
-
|
61
|
-
task :copyright do
|
62
|
-
sh "grep -q -r '2018-#{Date.today.strftime('%Y')}' \
|
63
|
-
--include '*.rb' \
|
64
|
-
--include '*.txt' \
|
65
|
-
--include 'Rakefile' \
|
66
|
-
."
|
67
52
|
end
|