cache_if_slow 0.0.1 → 0.0.2

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
2
  SHA256:
3
- metadata.gz: 55de8311ff8c4e0347c00eb3983925e35d4cebd6920e099670d2b308a0595a21
4
- data.tar.gz: c1e9f955ce113ecdf532fb2b3412e995fc22b62ac09c0e37cf59606af04b1c3b
3
+ metadata.gz: c57f6966f90b7576e367a8f31ca6af4ab34c8d0f7e4b787359af4080097c3ce3
4
+ data.tar.gz: 1701f933c543ba83921fcdf1feb8968f9f6d7289e43d8e79b59d7014a89266ff
5
5
  SHA512:
6
- metadata.gz: 8195a7315d595e852b0073d1f25277b8bc62633a7d37cac4d1bdb609674d6d1ba225efa8c3dcfa3e169af09351b75ed78dce27fdd17e2ef1cf804d6ba1c12ff2
7
- data.tar.gz: 060a7f5bd2d84d6de6296145bb2560a09d8662d8f09588c3ae7515c21993378b50e9e8d18765bba65c478273bed2d4ae82c9f2c4731ef1a69700974ccfada4a0
6
+ metadata.gz: 164cdd715ab74d08cda1a3b5bdf9b8b686dd194162c4acae2f29fcaba06c4b3c1efe054524ebdc4d6cd05352e4fec7df7e1871c2dfd58a09d396efdd07e859b8
7
+ data.tar.gz: 5e721f1180965e5516ff90c9952be2c2ca4a2b87b94e7034a8ff3b9d170b606af1ffa412f59b81ad4c1dc646583a6fd1cdd52c6a2998849d3500d5258db5b7f7
data/.rspec_status CHANGED
@@ -0,0 +1,6 @@
1
+ example_id | status | run_time |
2
+ --------------------------------------- | ------ | --------------- |
3
+ ./spec/cache_if_slow_spec.rb[1:1:1:1] | passed | 0.01229 seconds |
4
+ ./spec/cache_if_slow_spec.rb[1:1:2:1:1] | passed | 0.60579 seconds |
5
+ ./spec/cache_if_slow_spec.rb[1:1:2:2:1] | passed | 2.1 seconds |
6
+ ./spec/cache_if_slow_spec.rb[1:1:2:3:1] | passed | 0.30148 seconds |
data/README.md CHANGED
@@ -1 +1,101 @@
1
1
  # cache_if_slow
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/cache_if_slow.png)](https://badge.fury.io/rb/cache_if_slow)
4
+ [![CI Status](https://github.com/cianmce/cache_if_slow/actions/workflows/main.yml/badge.svg)](https://github.com/cianmce/cache_if_slow/actions)
5
+
6
+ Caches slow blocks of code using a cascading configuration.
7
+
8
+ ## Installation
9
+
10
+ ### Add gem
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'cache_if_slow'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle install
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install cache_if_slow
25
+
26
+ ## Usage
27
+
28
+ ### Create cache instance
29
+
30
+ `expiry_lookup` can be used to set the ttl for a given block of code.
31
+
32
+ With the below example, if a block of code took 1 -> 5 seconds, e.g. 2 seconds, then that result will be cached for 10 minutes. If it instead took over 10 seconds, then it would be cached for 30 minutes.
33
+
34
+ ```ruby
35
+ def self.cache
36
+ @cache ||= CacheIfSlow.new(expiry_lookup: [
37
+ { slower_than: 1.second, expires_in: 10.minutes },
38
+ { slower_than: 5.seconds, expires_in: 20.minutes },
39
+ { slower_than: 10.seconds, expires_in: 30.minutes }
40
+ ])
41
+ end
42
+ ```
43
+
44
+ ### `fetch` the result
45
+
46
+ This operates as a proxy to the [`Rails.cache.fetch`](https://apidock.com/rails/ActiveSupport/Cache/Store/fetch) method.
47
+
48
+ ```ruby
49
+ returned_value = self.class.cache.fetch("unique-cache-key") do
50
+ slow_request()
51
+ end
52
+ ```
53
+
54
+ ## Development
55
+
56
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
57
+
58
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
59
+
60
+ ### Testing
61
+ #### Run all specs + standardrb
62
+
63
+ ```sh
64
+ bundle exec rake
65
+ ```
66
+
67
+ #### Run only standardrb
68
+
69
+ ```sh
70
+ bundle exec rake standard
71
+ ````
72
+
73
+ #### Apply standardrb auto fixes
74
+
75
+ ```sh
76
+ bundle exec rake standard:fix
77
+ ```
78
+
79
+ #### Run specs using guard
80
+
81
+ ```sh
82
+ bundle exec guard
83
+ ```
84
+
85
+ This will auto run the related unit tests while you develop and save files.
86
+
87
+ ## Contributing
88
+
89
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cianmce/cache_if_slow. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/cianmce/cache_if_slow/blob/master/CODE_OF_CONDUCT.md).
90
+
91
+ ## License
92
+
93
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
94
+
95
+ ## Code of Conduct
96
+
97
+ Everyone interacting in the cache_if_slow project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/cianmce/cache_if_slow/blob/master/CODE_OF_CONDUCT.md).
98
+
99
+ ## TODO
100
+
101
+ - [ ] Update Readme and spec with class method examples
@@ -36,8 +36,5 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency "pry-doc", "~> 1.1"
37
37
  spec.add_development_dependency "guard", "~> 2.18"
38
38
  spec.add_development_dependency "guard-rspec", "~> 4.7.3"
39
- # spec.add_development_dependency "with_model", "~> 2.0"
40
- # spec.add_development_dependency "database_cleaner", "~> 1.5"
41
- # spec.add_development_dependency "sqlite3"
42
- spec.add_dependency "activesupport", ">= 4.0"
39
+ spec.add_dependency "rails", ">= 4.0"
43
40
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class CacheIfSlow
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
data/lib/cache_if_slow.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support"
3
+ require "rails"
4
4
  require "cache_if_slow/version"
5
5
 
6
6
  class CacheIfSlow
@@ -37,7 +37,7 @@ class CacheIfSlow
37
37
  if total_time > max_seconds && @cache.read(name, options).nil?
38
38
  expires_in = lookup_expiry(total_time, options)
39
39
  options[:expires_in] = expires_in
40
- @logger.info "CacheIfSlow :: Storing #{name} as #{total_time} > #{max_seconds} expires_in: #{expires_in}"
40
+ @logger.info "CacheIfSlow :: Storing '#{name}' as #{total_time} > #{max_seconds} expires_in: #{expires_in}"
41
41
  @cache.write(name, value, options)
42
42
  end
43
43
  value
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cache_if_slow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cian McElhinney
@@ -137,7 +137,7 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: 4.7.3
139
139
  - !ruby/object:Gem::Dependency
140
- name: activesupport
140
+ name: rails
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
@@ -178,7 +178,7 @@ licenses:
178
178
  metadata:
179
179
  homepage_uri: https://github.com/cianmce/cache_if_slow
180
180
  source_code_uri: https://github.com/cianmce/cache_if_slow
181
- documentation_uri: https://www.rubydoc.info/gems/cache_if_slow/0.0.1
181
+ documentation_uri: https://www.rubydoc.info/gems/cache_if_slow/0.0.2
182
182
  post_install_message:
183
183
  rdoc_options: []
184
184
  require_paths: