lightly 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -25
- data/lib/lightly/cache_operations.rb +1 -1
- data/lib/lightly/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d313f9708367bd12cd91e8a40edfead09bdab9abb923f1ba1b7cbd5129ff61e5
|
4
|
+
data.tar.gz: 6b19b9bf03a20d1725c5a9ef018a1e75fb945860195b158052dc74a0a0cc3de9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b1836e246ed0b7d2e3212fd9a273f390df4f34c992b1817ba326e11f12a23303c02c40bd398a3d633eb37c0761a59b7b268c125ef6d3b472a436ff93345b52d
|
7
|
+
data.tar.gz: 7023d499f4fa07b16c4580a0f6507970898cd507c097c1c7a88638174afe101c356e0435b290f78f0aedea8d578ccde2cea06fb3390ecf7b530275eaf4b74cf8
|
data/README.md
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
Lightly - Ruby File Cache
|
2
|
-
==================================================
|
1
|
+
# Lightly - Ruby File Cache
|
3
2
|
|
4
3
|
[![Gem Version](https://badge.fury.io/rb/lightly.svg)](https://badge.fury.io/rb/lightly)
|
5
|
-
[![Build Status](https://
|
4
|
+
[![Build Status](https://github.com/DannyBen/lightly/workflows/Test/badge.svg)](https://github.com/DannyBen/lightly/actions?query=workflow%3ATest)
|
6
5
|
[![Maintainability](https://api.codeclimate.com/v1/badges/8296395c9a332a15afc7/maintainability)](https://codeclimate.com/github/DannyBen/lightly/maintainability)
|
7
|
-
[![Test Coverage](https://api.codeclimate.com/v1/badges/8296395c9a332a15afc7/test_coverage)](https://codeclimate.com/github/DannyBen/lightly/test_coverage)
|
8
6
|
|
9
7
|
---
|
10
8
|
|
@@ -12,10 +10,9 @@ Lightly is a file cache for performing heavy tasks, lightly.
|
|
12
10
|
|
13
11
|
---
|
14
12
|
|
15
|
-
Install
|
16
|
-
--------------------------------------------------
|
13
|
+
## Install
|
17
14
|
|
18
|
-
```
|
15
|
+
```shell
|
19
16
|
$ gem install lightly
|
20
17
|
```
|
21
18
|
|
@@ -25,8 +22,7 @@ Or with bundler:
|
|
25
22
|
gem 'lightly'
|
26
23
|
```
|
27
24
|
|
28
|
-
Usage
|
29
|
-
--------------------------------------------------
|
25
|
+
## Usage
|
30
26
|
|
31
27
|
Lightly can be used both as an instance, and as a static class.
|
32
28
|
|
@@ -34,14 +30,14 @@ Lightly can be used both as an instance, and as a static class.
|
|
34
30
|
require 'lightly'
|
35
31
|
|
36
32
|
# Instance
|
37
|
-
|
38
|
-
response =
|
33
|
+
lightly = Lightly.new life: '3h'
|
34
|
+
response = lightly.get 'key' do
|
39
35
|
# Heavy operation here
|
40
36
|
end
|
41
37
|
|
42
38
|
# Static
|
43
39
|
Lightly.life = '3h'
|
44
|
-
Lightly.get 'key' do
|
40
|
+
response = Lightly.get 'key' do
|
45
41
|
# Heavy operation here
|
46
42
|
end
|
47
43
|
```
|
@@ -50,8 +46,8 @@ The design intention is to provide both a globally available singleton
|
|
50
46
|
`Lightly` object, as well as multiple caching instances, with different
|
51
47
|
settings - depending on the use case.
|
52
48
|
|
53
|
-
Note that the examples in this
|
54
|
-
all methods are also available statically.
|
49
|
+
Note that the examples in this document are all using the instance syntax,
|
50
|
+
but all methods are also available statically.
|
55
51
|
|
56
52
|
This is the basic usage pattern:
|
57
53
|
|
@@ -93,11 +89,11 @@ lightly.hash = false
|
|
93
89
|
The `life` property accepts any of these formats:
|
94
90
|
|
95
91
|
```ruby
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
92
|
+
lightly.life = 10 # 10 seconds
|
93
|
+
lightly.life = '20s' # 20 seconds
|
94
|
+
lightly.life = '10m' # 10 minutes
|
95
|
+
lightly.life = '10h' # 10 hours
|
96
|
+
lightly.life = '10d' # 10 days
|
101
97
|
```
|
102
98
|
|
103
99
|
To check if a key is cached, use the `cached?` method:
|
@@ -161,21 +157,28 @@ lightly = Lightly.new
|
|
161
157
|
lightly.prune
|
162
158
|
```
|
163
159
|
|
164
|
-
If your block returns false or nil
|
160
|
+
If your block returns `false` or `nil`, the data will not be cached:
|
165
161
|
|
166
162
|
```ruby
|
167
|
-
result =
|
163
|
+
result = lightly.get 'test' do
|
168
164
|
false
|
169
165
|
end
|
170
166
|
|
171
|
-
puts
|
167
|
+
puts lightly.cached? 'test'
|
172
168
|
# => false
|
173
169
|
```
|
174
170
|
|
175
|
-
|
171
|
+
## Related Projects
|
176
172
|
|
177
173
|
For a similar gem that provides caching specifically for HTTP downloads,
|
178
|
-
see the [WebCache gem][
|
174
|
+
see the [WebCache gem][webcache].
|
175
|
+
|
176
|
+
## Contributing / Support
|
179
177
|
|
178
|
+
If you experience any issue, have a question or a suggestion, or if you wish
|
179
|
+
to contribute, feel free to [open an issue][issues].
|
180
|
+
|
181
|
+
---
|
180
182
|
|
181
|
-
[
|
183
|
+
[webcache]: https://github.com/DannyBen/webcache
|
184
|
+
[issues]: https://github.com/DannyBen/lightly/issues
|
@@ -88,7 +88,7 @@ class Lightly
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def expired?(path)
|
91
|
-
expired = life
|
91
|
+
expired = life >= 0 && File.exist?(path) && Time.now - File.mtime(path) >= life
|
92
92
|
FileUtils.rm path if expired
|
93
93
|
expired
|
94
94
|
end
|
data/lib/lightly/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lightly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Easy to use file cache
|
14
14
|
email: db@dannyben.com
|
@@ -40,8 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
requirements: []
|
43
|
-
|
44
|
-
rubygems_version: 2.7.6
|
43
|
+
rubygems_version: 3.1.2
|
45
44
|
signing_key:
|
46
45
|
specification_version: 4
|
47
46
|
summary: File cache for performing heavy tasks, lightly.
|