zache 0.12.0 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2403a36c273eae3e483b5ae85d80eed0927e18ade783dca22acbd21ec7ea04d4
4
- data.tar.gz: '06982ecbca83f8fd07c69546615b9a04d918a6ccd4743c03716d7ef609c35842'
3
+ metadata.gz: b87b15cc2d21dd690255c612d9e3ea5d28f1b4788cfa19c239f3bcc6b29144e1
4
+ data.tar.gz: ea6a615b74dbec67e97d1c8d5db0b467380030d01635964e25c031e13e490fcc
5
5
  SHA512:
6
- metadata.gz: d1865b4876a8e2ebd39c6032be88fdb42231e57d5507f889a7fec75d270a2254c9d80557c8a6dc6a213c24354bcc6514fd226c91d618fff3bc386d7cf9f7882a
7
- data.tar.gz: 2dd7862a048d3cf615c1b93bf1261d0a208e4fd7acd424ed2516e032b05d2ac7050fbd1f06d1c5457d36c19073e8bd6fd4ce31d22323cf101adecdf6be1820a3
6
+ metadata.gz: 6e9c8cb157905d795cb96650b8f5d71cb79b5b0575e03863df23df485c9e708f4e09d552ee0330b4f78fa373c14ef232b16b574d3afb0a310ad02d2f51732f34
7
+ data.tar.gz: 97d726f208f8ac511b8ecfac2b9602bae716bec22d0b3e56e9bc77c36ccf97efaaee73ccb4d9057f071f26ea52da9afafb6eafd88f9c2e6c46f2d1c561da3e9c
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: codecov
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ jobs:
8
+ codecov:
9
+ runs-on: ubuntu-20.04
10
+ steps:
11
+ - uses: actions/checkout@v3
12
+ - uses: actions/setup-ruby@v1
13
+ with:
14
+ ruby-version: 3.0
15
+ - run: bundle update
16
+ - run: bundle exec rake
17
+ - uses: codecov/codecov-action@v3
18
+ with:
19
+ file: coverage/.resultset.json
20
+ fail_ci_if_error: true
@@ -0,0 +1,15 @@
1
+ ---
2
+ name: pdd
3
+ "on":
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+ jobs:
11
+ pdd:
12
+ runs-on: ubuntu-20.04
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ - uses: g4s8/pdd-action@master
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: rake
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+ jobs:
11
+ test:
12
+ name: test
13
+ strategy:
14
+ matrix:
15
+ os: [ubuntu-20.04, macos-12]
16
+ ruby: [3.0, 2.7]
17
+ runs-on: ${{ matrix.os }}
18
+ steps:
19
+ - uses: actions/checkout@v3
20
+ - uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+ - run: bundle update
24
+ - run: bundle exec rake
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: xcop
3
+ "on":
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+ jobs:
11
+ xcop:
12
+ runs-on: ubuntu-20.04
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ - uses: g4s8/xcop-action@master
16
+ with:
17
+ files: '**/*.xml'
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ Gemfile.lock
4
4
  .DS_Store
5
5
  rdoc/
6
6
  .idea/
7
+ coverage/
data/.rubocop.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  AllCops:
2
2
  DisplayCopNames: true
3
3
  TargetRubyVersion: 2.5
4
+ NewCops: enable
5
+ SuggestExtensions: false
4
6
 
5
7
  Metrics/ClassLength:
6
8
  Exclude:
@@ -17,3 +19,7 @@ Metrics/CyclomaticComplexity:
17
19
  Max: 12
18
20
  Metrics/PerceivedComplexity:
19
21
  Max: 12
22
+ Layout/EndOfLine:
23
+ EnforcedStyle: lf
24
+ Metrics/BlockLength:
25
+ Max: 28
data/.rultor.yml CHANGED
@@ -1,12 +1,14 @@
1
+ docker:
2
+ image: yegor256/rultor-image:1.19.0
1
3
  assets:
2
- rubygems.yml: zerocracy/home#assets/rubygems.yml
3
- install: |-
4
- export GEM_HOME=~/.ruby
5
- export GEM_PATH=$GEM_HOME:$GEM_PATH
4
+ rubygems.yml: yegor256/home#assets/rubygems.yml
5
+ install: |
6
+ pdd -f /dev/null
7
+ sudo bundle install --no-color "--gemfile=$(pwd)/Gemfile"
6
8
  release:
7
9
  script: |-
8
- bundle install
9
- rake
10
+ bundle exec rake
11
+ pdd -f /dev/null
10
12
  rm -rf *.gem
11
13
  sed -i "s/0\.0\.0/${tag}/g" zache.gemspec
12
14
  git add zache.gemspec
@@ -14,13 +16,6 @@ release:
14
16
  gem build zache.gemspec
15
17
  chmod 0600 ../rubygems.yml
16
18
  gem push *.gem --config-file ../rubygems.yml
17
- commanders:
18
- - yegor256
19
- architect:
20
- - yegor256
21
19
  merge:
22
- commanders: []
23
20
  script: |-
24
- bundle install
25
- rake
26
- deploy: {}
21
+ bundle exec rake clean test rubocop copyright
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018 Yegor Bugayenko
3
+ # Copyright (c) 2018-2023 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
@@ -21,5 +21,13 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  source 'https://rubygems.org'
24
- ruby '2.6.0'
25
24
  gemspec
25
+
26
+ gem 'concurrent-ruby', '1.2.2', require: false
27
+ gem 'minitest', '5.19.0', require: false
28
+ gem 'rake', '13.0.6', require: false
29
+ gem 'rdoc', '6.5.0', require: false
30
+ gem 'rubocop', '1.55.1', require: false
31
+ gem 'rubocop-rspec', '2.23.0', require: false
32
+ gem 'simplecov', '0.22.0', require: false
33
+ gem 'threads', '0.3.0', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018-2023 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,14 +1,20 @@
1
- [![EO principles respected here](http://www.elegantobjects.org/badge.svg)](http://www.elegantobjects.org)
1
+ <img src="/logo.svg" width="64px" height="64px"/>
2
+
3
+ [![EO principles respected here](https://www.elegantobjects.org/badge.svg)](https://www.elegantobjects.org)
2
4
  [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/zache)](http://www.rultor.com/p/yegor256/zache)
3
- [![We recommend RubyMine](http://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
5
+ [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
4
6
 
5
- [![Build Status](https://travis-ci.org/yegor256/zache.svg)](https://travis-ci.org/yegor256/zache)
6
- [![Build status](https://ci.appveyor.com/api/projects/status/7eday736u9phnjiy?svg=true)](https://ci.appveyor.com/project/yegor256/zache)
7
+ [![rake](https://github.com/yegor256/zache/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/zache/actions/workflows/rake.yml)
7
8
  [![Gem Version](https://badge.fury.io/rb/zache.svg)](http://badge.fury.io/rb/zache)
8
9
  [![Maintainability](https://api.codeclimate.com/v1/badges/c136afe340fa94f14696/maintainability)](https://codeclimate.com/github/yegor256/zache/maintainability)
9
10
  [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/zache/master/frames)
11
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/zache/blob/master/LICENSE.txt)
12
+ [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/zache.svg)](https://codecov.io/github/yegor256/zache?branch=master)
13
+ [![Hits-of-Code](https://hitsofcode.com/github/yegor256/zache)](https://hitsofcode.com/view/github/yegor256/zache)
10
14
 
11
15
  It's a simple Ruby gem for in-memory cache.
16
+ Read [this blog post](https://www.yegor256.com/2019/02/05/zache.html)
17
+ to understand what Zache is for.
12
18
 
13
19
  First, install it:
14
20
 
@@ -40,9 +46,12 @@ while another one calls `get` again. That second thread won't wait, but will
40
46
  receive what's left in the cache. This is a very convenient mode for situations
41
47
  when you don't really care about data accuracy, but performance is an issue.
42
48
 
49
+ The entire API is documented [here](https://www.rubydoc.info/github/yegor256/zache/master/Zache)
50
+ (there are many other convenient methods).
51
+
43
52
  That's it.
44
53
 
45
- # How to contribute
54
+ ## How to contribute
46
55
 
47
56
  Read [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
48
57
  Make sure you build is green before you contribute
@@ -51,31 +60,7 @@ your pull request. You will need to have [Ruby](https://www.ruby-lang.org/en/) 2
51
60
 
52
61
  ```
53
62
  $ bundle update
54
- $ rake
63
+ $ bundle exec rake
55
64
  ```
56
65
 
57
66
  If it's clean and you don't see any error messages, submit your pull request.
58
-
59
- # License
60
-
61
- (The MIT License)
62
-
63
- Copyright (c) 2018 Yegor Bugayenko
64
-
65
- Permission is hereby granted, free of charge, to any person obtaining a copy
66
- of this software and associated documentation files (the 'Software'), to deal
67
- in the Software without restriction, including without limitation the rights
68
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
69
- copies of the Software, and to permit persons to whom the Software is
70
- furnished to do so, subject to the following conditions:
71
-
72
- The above copyright notice and this permission notice shall be included in all
73
- copies or substantial portions of the Software.
74
-
75
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
76
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
77
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
78
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
79
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
80
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
81
- SOFTWARE.
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018 Yegor Bugayenko
3
+ # Copyright (c) 2018-2023 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
@@ -34,7 +34,7 @@ def version
34
34
  Gem::Specification.load(Dir['*.gemspec'].first).version
35
35
  end
36
36
 
37
- task default: %i[clean test rubocop]
37
+ task default: %i[clean test rubocop copyright]
38
38
 
39
39
  require 'rake/testtask'
40
40
  desc 'Run all unit tests'
@@ -57,3 +57,11 @@ RuboCop::RakeTask.new(:rubocop) do |task|
57
57
  task.fail_on_error = true
58
58
  task.requires << 'rubocop-rspec'
59
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
+ end
data/lib/zache.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # (The MIT License)
4
4
  #
5
- # Copyright (c) 2018 Yegor Bugayenko
5
+ # Copyright (c) 2018-2023 Yegor Bugayenko
6
6
  #
7
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  # of this software and associated documentation files (the 'Software'), to deal
@@ -34,7 +34,7 @@
34
34
  # {README}[https://github.com/yegor256/zache/blob/master/README.md] file.
35
35
  #
36
36
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
37
- # Copyright:: Copyright (c) 2018 Yegor Bugayenko
37
+ # Copyright:: Copyright (c) 2018-2023 Yegor Bugayenko
38
38
  # License:: MIT
39
39
  class Zache
40
40
  # Fake implementation that doesn't cache anything, but behaves like it
@@ -67,6 +67,7 @@ class Zache
67
67
  end
68
68
 
69
69
  # Makes a new object of the cache.
70
+ #
70
71
  # "sync" is whether the hash is thread-safe (`true`)
71
72
  # or not (`false`); it is recommended to leave this parameter untouched,
72
73
  # unless you really know what you are doing.
@@ -85,7 +86,9 @@ class Zache
85
86
  @hash.size
86
87
  end
87
88
 
88
- # Gets the value from the cache by the provided key. If the value is not
89
+ # Gets the value from the cache by the provided key.
90
+ #
91
+ # If the value is not
89
92
  # found in the cache, it will be calculated via the provided block. If
90
93
  # the block is not given, an exception will be raised (unless <tt>dirty</tt>
91
94
  # is set to <tt>true</tt>). The lifetime
@@ -94,12 +97,10 @@ class Zache
94
97
  #
95
98
  # If the <tt>dirty</tt> argument is set to <tt>true</tt>, a previously
96
99
  # calculated result will be returned if it exists and is already expired.
97
- def get(key, lifetime: 2**32, dirty: false)
100
+ def get(key, lifetime: 2**32, dirty: false, &block)
98
101
  if block_given?
99
- if (dirty || @dirty) && locked? && expired?(key) && @hash.key?(key)
100
- return @hash[key][:value]
101
- end
102
- synchronized { calc(key, lifetime) { yield } }
102
+ return @hash[key][:value] if (dirty || @dirty) && locked? && expired?(key) && @hash.key?(key)
103
+ synchronized { calc(key, lifetime, &block) }
103
104
  else
104
105
  rec = @hash[key]
105
106
  if expired?(key)
@@ -155,7 +156,7 @@ class Zache
155
156
  end
156
157
 
157
158
  # Removes the value from the hash, by the provied key. If the key is absent
158
- # and the block is provide, the block will be called.
159
+ # and the block is provided, the block will be called.
159
160
  def remove(key)
160
161
  synchronized { @hash.delete(key) { yield if block_given? } }
161
162
  end
@@ -168,7 +169,7 @@ class Zache
168
169
  # Remove all keys that match the block.
169
170
  def remove_by
170
171
  synchronized do
171
- @hash.keys.each do |k|
172
+ @hash.each_key do |k|
172
173
  @hash.delete(k) if yield(k)
173
174
  end
174
175
  end
@@ -194,17 +195,11 @@ class Zache
194
195
  @hash[key][:value]
195
196
  end
196
197
 
197
- def synchronized
198
+ def synchronized(&block)
198
199
  if @sync
199
- @mutex.synchronize do
200
- # I don't know why, but if you remove this line, the tests will
201
- # break. It seems to me that there is a bug in Ruby. Let's try to
202
- # fix it or find a workaround and remove this line.
203
- sleep 0.00001
204
- yield
205
- end
200
+ @mutex.synchronize(&block)
206
201
  else
207
- yield
202
+ block.call
208
203
  end
209
204
  end
210
205
  end
data/logo.svg ADDED
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="314px" height="314px" viewBox="0 0 314 314" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <!-- Generator: Sketch 43.2 (39069) - http://www.bohemiancoding.com/sketch -->
4
+ <title>Group 2</title>
5
+ <desc>Created with Sketch.</desc>
6
+ <defs></defs>
7
+ <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
8
+ <g id="Group-2">
9
+ <g id="Group">
10
+ <circle id="Oval" fill="#053C5E" cx="157" cy="157" r="157"></circle>
11
+ <rect id="Rectangle" fill="#2B2B2B" x="0" y="234" width="212" height="68"></rect>
12
+ <text id="zache" font-family="CourierNewPS-BoldMT, Courier New" font-size="50" font-weight="bold" fill="#FFFFFF">
13
+ <tspan x="28" y="282">zache</tspan>
14
+ </text>
15
+ <path d="M135.676765,111.215287 C135.211714,113.540467 132.770932,120.688823 130.252813,127.100603 C127.734621,133.512383 125.2898,140.431445 124.819828,142.476214 C123.6868,147.405663 121.517836,147.185477 119.69487,141.95608 C116.899865,133.938362 105.171362,111.043501 103.859129,111.043501 C100.420089,111.043501 101.508757,114.986149 109.1771,130.30227 C113.739327,139.414532 118.032086,147.448041 118.716515,148.15443 C120.694817,150.196115 120.172626,154.319657 117.358599,158.877992 C113.567467,165.019055 107.570942,183.721189 108.054206,187.896804 C108.804956,194.383204 112.436054,192.210274 113.355359,184.724515 C114.48376,175.535577 120.945556,159.641154 124.897459,156.333653 C127.109021,154.482778 128.268636,151.905536 128.573284,148.163978 C128.818001,145.157747 131.906711,135.560972 135.437115,126.837819 C138.96752,118.114666 141.511492,110.079835 141.090434,108.982574 C139.755727,105.504315 136.554941,106.824333 135.676765,111.215287 M174.714659,126.841564 C169.37392,129.699438 169.197653,130.049915 167.452978,141.283475 C165.577352,153.360398 165.225112,168.513913 166.548289,180.203784 L167.566817,189.202501 L161.346213,191.9541 C154.601949,194.937416 150.91195,200.302465 153.156708,203.861146 C155.104824,206.949562 157.09025,206.70198 157.571826,203.310532 C158.083734,199.706169 166.097413,193.204052 170.29418,192.987978 C172.116999,192.894116 173.522874,191.717021 173.97823,189.903529 C174.383277,188.290613 177.740353,184.944554 181.438431,182.467858 C188.546172,177.707551 194.317883,170.450278 194.317883,166.273341 C194.317883,162.684548 189.493165,158.361603 185.487795,158.361603 C180.701636,158.361603 180.027195,155.239403 183.731222,150.229385 C188.308065,144.038966 188.284856,130.867646 183.690534,127.147387 C179.896537,124.075276 179.885006,124.074836 174.714659,126.841564 M182.67318,134.240439 C184.752542,140.153164 174.808961,161.185104 171.588639,157.68562 C169.868715,155.81653 172.863122,135.012708 175.266374,132.134564 C177.872553,129.013319 181.163896,129.949075 182.67318,134.240439 M184.854262,162.269586 C190.589839,163.855621 189.673839,167.881335 181.645765,176.371155 C177.281618,180.986262 173.904933,183.573859 173.371946,182.711474 C172.876636,181.91012 172.127869,176.711937 171.707987,171.159972 L170.944531,161.065463 L176.209475,161.200234 C179.105172,161.274339 182.995308,161.755548 184.854262,162.269586 M132.642184,172.492256 C131.593837,175.224098 133.152917,177.288844 136.264027,177.288844 C139.014965,177.288844 139.431396,176.221769 138.067531,172.667568 C137.039234,169.987871 133.645289,169.878218 132.642184,172.492256 M203.781503,185.840798 C203.781503,187.657595 209.264724,193.512152 210.966361,193.512152 C212.534035,193.512152 211.991059,187.391138 210.270768,185.670847 C208.092403,183.492409 203.781503,183.605293 203.781503,185.840798" id="Fill-6" fill="#427B8A" fill-rule="nonzero"></path>
16
+ </g>
17
+ </g>
18
+ </g>
19
+ </svg>
data/renovate.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": [
4
+ "config:base"
5
+ ]
6
+ }
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2018-2023 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 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 NONINFINGEMENT. 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.
22
+
23
+ $stdout.sync = true
24
+
25
+ require 'simplecov'
26
+ SimpleCov.start
27
+ require 'minitest/autorun'
28
+ require_relative '../lib/zache'
data/test/test_zache.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # (The MIT License)
4
4
  #
5
- # Copyright (c) 2018 Yegor Bugayenko
5
+ # Copyright (c) 2018-2023 Yegor Bugayenko
6
6
  #
7
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  # of this software and associated documentation files (the 'Software'), to deal
@@ -32,7 +32,7 @@ Thread.report_on_exception = true
32
32
 
33
33
  # Cache test.
34
34
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
35
- # Copyright:: Copyright (c) 2018 Yegor Bugayenko
35
+ # Copyright:: Copyright (c) 2018-2023 Yegor Bugayenko
36
36
  # License:: MIT
37
37
  class ZacheTest < Minitest::Test
38
38
  def test_caches
@@ -74,6 +74,13 @@ class ZacheTest < Minitest::Test
74
74
  assert(not_exists_result == false)
75
75
  end
76
76
 
77
+ def test_put_and_exists
78
+ cache = Zache.new
79
+ cache.put(:hey, 'hello', lifetime: 0.1)
80
+ sleep 0.2
81
+ assert(!cache.exists?(:hey))
82
+ end
83
+
77
84
  def test_remove_key
78
85
  cache = Zache.new
79
86
  cache.get(:hey) { Random.rand }
@@ -247,7 +254,9 @@ class ZacheTest < Minitest::Test
247
254
  cache = Zache.new(dirty: true)
248
255
  set = Concurrent::Set.new
249
256
  threads = 50
257
+ barrier = Concurrent::CyclicBarrier.new(threads)
250
258
  Threads.new(threads).assert(threads * 2) do |i|
259
+ barrier.wait if i < threads
251
260
  set << cache.get(i, lifetime: 0.001) { i }
252
261
  end
253
262
  assert_equal(threads, set.size)
@@ -257,7 +266,9 @@ class ZacheTest < Minitest::Test
257
266
  cache = Zache.new
258
267
  set = Concurrent::Set.new
259
268
  threads = 50
269
+ barrier = Concurrent::CyclicBarrier.new(threads)
260
270
  Threads.new(threads).assert(threads * 2) do |i|
271
+ barrier.wait if i < threads
261
272
  set << cache.get(i) { i }
262
273
  end
263
274
  assert_equal(threads, set.size)
@@ -267,4 +278,11 @@ class ZacheTest < Minitest::Test
267
278
  cache = Zache::Fake.new
268
279
  assert_equal(1, cache.get(:x) { 1 })
269
280
  end
281
+
282
+ def test_rethrows
283
+ cache = Zache.new
284
+ assert_raises RuntimeError do
285
+ cache.get(:hey) { raise 'intentional' }
286
+ end
287
+ end
270
288
  end
data/zache.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # (The MIT License)
4
4
  #
5
- # Copyright (c) 2018 Yegor Bugayenko
5
+ # Copyright (c) 2018-2023 Yegor Bugayenko
6
6
  #
7
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  # of this software and associated documentation files (the 'Software'), to deal
@@ -24,14 +24,10 @@
24
24
 
25
25
  require 'English'
26
26
  Gem::Specification.new do |s|
27
- s.specification_version = 2 if s.respond_to? :specification_version=
28
- if s.respond_to? :required_rubygems_version=
29
- s.required_rubygems_version = Gem::Requirement.new('>= 0')
30
- end
31
- s.rubygems_version = '2.5'
27
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
32
28
  s.required_ruby_version = '>=2.5'
33
29
  s.name = 'zache'
34
- s.version = '0.12.0'
30
+ s.version = '0.13.1'
35
31
  s.license = 'MIT'
36
32
  s.summary = 'In-memory Cache'
37
33
  s.description = 'Zero-footprint in-memory thread-safe cache'
@@ -39,14 +35,7 @@ Gem::Specification.new do |s|
39
35
  s.email = 'yegor256@gmail.com'
40
36
  s.homepage = 'http://github.com/yegor256/zache'
41
37
  s.files = `git ls-files`.split($RS)
42
- s.test_files = s.files.grep(%r{^(test)/})
43
38
  s.rdoc_options = ['--charset=UTF-8']
44
39
  s.extra_rdoc_files = ['README.md']
45
- s.add_development_dependency 'concurrent-ruby', '1.1.3'
46
- s.add_development_dependency 'minitest', '5.11.3'
47
- s.add_development_dependency 'rake', '12.3.1'
48
- s.add_development_dependency 'rdoc', '4.3.0'
49
- s.add_development_dependency 'rubocop', '0.62.0'
50
- s.add_development_dependency 'rubocop-rspec', '1.31.0'
51
- s.add_development_dependency 'threads', '0.3.0'
40
+ s.metadata['rubygems_mfa_required'] = 'true'
52
41
  end
metadata CHANGED
@@ -1,113 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-30 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: concurrent-ruby
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '='
18
- - !ruby/object:Gem::Version
19
- version: 1.1.3
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '='
25
- - !ruby/object:Gem::Version
26
- version: 1.1.3
27
- - !ruby/object:Gem::Dependency
28
- name: minitest
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '='
32
- - !ruby/object:Gem::Version
33
- version: 5.11.3
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '='
39
- - !ruby/object:Gem::Version
40
- version: 5.11.3
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '='
46
- - !ruby/object:Gem::Version
47
- version: 12.3.1
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '='
53
- - !ruby/object:Gem::Version
54
- version: 12.3.1
55
- - !ruby/object:Gem::Dependency
56
- name: rdoc
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '='
60
- - !ruby/object:Gem::Version
61
- version: 4.3.0
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '='
67
- - !ruby/object:Gem::Version
68
- version: 4.3.0
69
- - !ruby/object:Gem::Dependency
70
- name: rubocop
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - '='
74
- - !ruby/object:Gem::Version
75
- version: 0.62.0
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '='
81
- - !ruby/object:Gem::Version
82
- version: 0.62.0
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop-rspec
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - '='
88
- - !ruby/object:Gem::Version
89
- version: 1.31.0
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '='
95
- - !ruby/object:Gem::Version
96
- version: 1.31.0
97
- - !ruby/object:Gem::Dependency
98
- name: threads
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - '='
102
- - !ruby/object:Gem::Version
103
- version: 0.3.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.3.0
11
+ date: 2023-08-01 00:00:00.000000000 Z
12
+ dependencies: []
111
13
  description: Zero-footprint in-memory thread-safe cache
112
14
  email: yegor256@gmail.com
113
15
  executables: []
@@ -116,22 +18,29 @@ extra_rdoc_files:
116
18
  - README.md
117
19
  files:
118
20
  - ".0pdd.yml"
21
+ - ".github/workflows/codecov.yml"
22
+ - ".github/workflows/pdd.yml"
23
+ - ".github/workflows/rake.yml"
24
+ - ".github/workflows/xcop.yml"
119
25
  - ".gitignore"
120
26
  - ".pdd"
121
27
  - ".rubocop.yml"
122
28
  - ".rultor.yml"
123
- - ".travis.yml"
124
29
  - Gemfile
30
+ - LICENSE.txt
125
31
  - README.md
126
32
  - Rakefile
127
- - appveyor.yml
128
33
  - lib/zache.rb
34
+ - logo.svg
35
+ - renovate.json
36
+ - test/test__helper.rb
129
37
  - test/test_zache.rb
130
38
  - zache.gemspec
131
39
  homepage: http://github.com/yegor256/zache
132
40
  licenses:
133
41
  - MIT
134
- metadata: {}
42
+ metadata:
43
+ rubygems_mfa_required: 'true'
135
44
  post_install_message:
136
45
  rdoc_options:
137
46
  - "--charset=UTF-8"
@@ -148,9 +57,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
57
  - !ruby/object:Gem::Version
149
58
  version: '0'
150
59
  requirements: []
151
- rubygems_version: 3.0.1
60
+ rubygems_version: 3.2.15
152
61
  signing_key:
153
- specification_version: 2
62
+ specification_version: 4
154
63
  summary: In-memory Cache
155
- test_files:
156
- - test/test_zache.rb
64
+ test_files: []
data/.travis.yml DELETED
@@ -1,12 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3.3
4
- branches:
5
- only:
6
- - master
7
- install:
8
- - bundle install
9
- script:
10
- - set -e
11
- - rake
12
-
data/appveyor.yml DELETED
@@ -1,38 +0,0 @@
1
- version: '{build}'
2
- skip_tags: true
3
- clone_depth: 10
4
- branches:
5
- only:
6
- - master
7
- except:
8
- - gh-pages
9
- os: Windows Server 2012
10
- environment:
11
- matrix:
12
- - ruby_version: "23-x64"
13
- - ruby_version: "24-x64"
14
- - ruby_version: "25-x64"
15
- install:
16
- - ps: |
17
- $Env:PATH = "C:\Ruby${Env:ruby_version}\bin;${Env:PATH}"
18
- if ($Env:ruby_version -match "^23" ) {
19
- # RubyInstaller; download OpenSSL headers from OpenKnapsack Project
20
- $Env:openssl_dir = "C:\Ruby${Env:ruby_version}"
21
- appveyor DownloadFile http://dl.bintray.com/oneclick/OpenKnapsack/x64/openssl-1.0.2j-x64-windows.tar.lzma
22
- 7z e openssl-1.0.2j-x64-windows.tar.lzma
23
- 7z x -y -oC:\Ruby${Env:ruby_version} openssl-1.0.2j-x64-windows.tar
24
- } else {
25
- # RubyInstaller2; openssl package seems to be installed already
26
- $Env:openssl_dir = "C:\msys64\mingw64"
27
- }
28
- - bundle config --local path vendor/bundle
29
- - bundle config build.openssl --with-openssl-dir=%openssl_dir%
30
- - ruby -v
31
- - bundle -v
32
- build_script:
33
- - bundle update
34
- - bundle install
35
- test_script:
36
- - bundle exec rake --quiet
37
- cache:
38
- - vendor/bundle