twingly-url_cache 1.0.1 → 3.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b9ed893f285e11aefe16536d0dbff6dd75d2e1e9
4
- data.tar.gz: 92fa6a2cfc57232d56e0b89542556a9ce8f484ae
2
+ SHA256:
3
+ metadata.gz: 1ed2d18cc27d219c6d13d00683ba7b3452e3f4e1820706d538c86f7ea102515c
4
+ data.tar.gz: de311bd4e8dddc0c8d0d28aaf48c56bd49940920d12a0c233261eee0e1b24536
5
5
  SHA512:
6
- metadata.gz: 938656877cb25f56db3ccb9b88c8196329fd1b8982bc613c53b1b51be5a08a7f4c55ba52eb2953fe886d8daea8fc85266d7d33f820a677d4bf0d7a2048a720d7
7
- data.tar.gz: 21a983f60abfc1a58a3ff76a42ab9f01e53057d734e7ba3d90263a63a2e9156d423f7ffeae5a8246df195ba32a6f0c2747d77efd5d45ce1fd8fbc44bdc4cde88
6
+ metadata.gz: 8f50e165dbb8716c6fbbb3ada282e1d2e41a03579a7d9905853dcbcfe92c3c16014979e074d165f3889db0edcffac7b622e215222df6c99533fc914db4e17c90
7
+ data.tar.gz: 38c9491b219f5e951e0a8a438402674e941c7c639e6c33486cd7f8b063e2595afbce60d69e4789df4f72cf81c4571ee888d44a4e5958a05029da0e83859c05db
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Twingly::UrlCache
2
2
 
3
+ [![GitHub Build Status](https://github.com/twingly/twingly-url_cache/workflows/CI/badge.svg?branch=master)](https://github.com/twingly/twingly-url_cache/actions)
4
+
3
5
  URL cache, remember if an URL been seen before. Uses [Memcached] to cache data, prefers [MemCachier].
4
6
 
5
7
  [Memcached]: http://memcached.org/
@@ -36,10 +38,10 @@ Initialize an instance, cache an URL with `#cache!` and look if it's cached with
36
38
  => false
37
39
  ```
38
40
 
39
- Required environment variables:
41
+ Optional environment variables:
40
42
 
41
43
  ```Shell
42
- MEMCACHIER_SERVERS
44
+ MEMCACHIER_SERVERS # Defaults to localhost
43
45
  MEMCACHIER_PASSWORD
44
46
  MEMCACHIER_USERNAME
45
47
  ```
@@ -48,9 +50,26 @@ MEMCACHIER_USERNAME
48
50
 
49
51
  After checking out the repo, run `bin/setup` to install dependencies. Start memcached. Then, run `bundle exec rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
52
 
51
- 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).
53
+ To install this gem onto your local machine, run `bundle exec rake install`.
54
+
55
+ ## Release workflow
56
+
57
+ * Update the examples in this README if needed.
58
+
59
+ * Bump the version in `lib/twingly/url_cache/version.rb` in a commit, no need to push (the release task does that).
60
+
61
+ * Ensure you are signed in to RubyGems.org as [twingly][twingly-rubygems] with `gem signin`.
62
+
63
+ * Build and [publish](http://guides.rubygems.org/publishing/) the gem. This will create the proper tag in git, push the commit and tag and upload to RubyGems.
64
+
65
+ bundle exec rake release
66
+
67
+ * Update the changelog with [GitHub Changelog Generator](https://github.com/skywinder/github-changelog-generator/) (`gem install github_changelog_generator` if you don't have it, set `CHANGELOG_GITHUB_TOKEN` to a personal access token to avoid rate limiting by GitHub). This command will update `CHANGELOG.md`. You need to commit and push manually.
68
+
69
+ github_changelog_generator -u twingly -p twingly-url_cache
70
+
71
+ [twingly-rubygems]: https://rubygems.org/profiles/twingly
52
72
 
53
73
  ## Contributing
54
74
 
55
75
  Bug reports and pull requests are welcome on GitHub at https://github.com/twingly/twingly-url_cache.
56
-
@@ -1,5 +1,5 @@
1
1
  module Twingly
2
2
  class UrlCache
3
- VERSION = "1.0.1"
3
+ VERSION = "3.0.0"
4
4
  end
5
5
  end
@@ -5,26 +5,35 @@ require "retryable"
5
5
 
6
6
  module Twingly
7
7
  class UrlCache
8
+ class Error < StandardError; end
9
+ class ServerError < Error; end
10
+
8
11
  attr_reader :ttl
9
12
 
10
13
  CACHE_VALUE = ""
11
14
 
12
- def initialize(ttl: 0)
13
- @cache = Dalli::Client.new(servers, options)
14
- @ttl = ttl
15
+ def initialize(ttl: 0, cache: default_cache)
16
+ @ttl = ttl
17
+ @cache = cache
15
18
  end
16
19
 
17
20
  def cache!(url)
18
21
  key = key_for(url)
19
- Retryable.retryable(tries: 3, on: Dalli::RingError) do
20
- !!@cache.set(key, CACHE_VALUE, ttl, raw: true)
22
+
23
+ retry_transient_exceptions do
24
+ with_exception_class_conversion do
25
+ !!@cache.set(key, CACHE_VALUE, ttl, raw: true)
26
+ end
21
27
  end
22
28
  end
23
29
 
24
30
  def cached?(url)
25
31
  key = key_for(url)
26
- Retryable.retryable(tries: 3, on: Dalli::RingError) do
27
- @cache.get(key, raw: true) == CACHE_VALUE
32
+
33
+ retry_transient_exceptions do
34
+ with_exception_class_conversion do
35
+ @cache.get(key, raw: true) == CACHE_VALUE
36
+ end
28
37
  end
29
38
  end
30
39
 
@@ -34,6 +43,14 @@ module Twingly
34
43
  Digest::MD5.digest(url)
35
44
  end
36
45
 
46
+ def default_cache
47
+ retry_transient_exceptions do
48
+ with_exception_class_conversion do
49
+ Dalli::Client.new(servers, options)
50
+ end
51
+ end
52
+ end
53
+
37
54
  def options
38
55
  {
39
56
  username: ENV.fetch("MEMCACHIER_USERNAME") { },
@@ -45,8 +62,19 @@ module Twingly
45
62
  end
46
63
 
47
64
  def servers
48
- ENV.fetch("MEMCACHIER_SERVERS").split(",")
65
+ ENV.fetch("MEMCACHIER_SERVERS") { "localhost" }.split(",")
66
+ end
67
+
68
+ def with_exception_class_conversion
69
+ yield
70
+ rescue Dalli::RingError => error
71
+ raise ServerError, error.message
72
+ rescue Dalli::DalliError => error
73
+ raise Error, error.message
74
+ end
75
+
76
+ def retry_transient_exceptions(&block)
77
+ Retryable.retryable(tries: 3, on: ServerError, &block)
49
78
  end
50
79
  end
51
80
  end
52
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twingly-url_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Twingly AB
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-22 00:00:00.000000000 Z
11
+ date: 2022-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dalli
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.7'
19
+ version: 3.2.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.7'
26
+ version: 3.2.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: retryable
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,34 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.10'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.10'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '10.0'
47
+ version: '12'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '10.0'
54
+ version: '12'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rspec
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -107,7 +93,7 @@ files:
107
93
  homepage: https://github.com/twingly/twingly-url_cache
108
94
  licenses: []
109
95
  metadata: {}
110
- post_install_message:
96
+ post_install_message:
111
97
  rdoc_options: []
112
98
  require_paths:
113
99
  - lib
@@ -122,9 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
108
  - !ruby/object:Gem::Version
123
109
  version: '0'
124
110
  requirements: []
125
- rubyforge_project:
126
- rubygems_version: 2.4.5.1
127
- signing_key:
111
+ rubygems_version: 3.3.7
112
+ signing_key:
128
113
  specification_version: 4
129
114
  summary: URL cache, remember if an URL been seen before
130
115
  test_files: []