ractor-cache 0.1.0 → 0.2.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/README.md +3 -1
- data/lib/ractor/cache/strategy.rb +16 -9
- data/lib/ractor/cache/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2fb8ce98adad688d2ff0e150265154ba963c62a4c7cd88e87bb09ab366db535
|
4
|
+
data.tar.gz: fda4eb8307bb638e87841f418895c4f57297c975349c9502026b3346ad570256
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38ad35d50bf189e0dc9f0da88f91f484664811824f1310e2e4a040f49b19d3f9f079c826d9667956d5d3ec4949e440583f7f38d74c6f6841af40a9f65b672453
|
7
|
+
data.tar.gz: fa23e9e4cebd2891ba3bfdfe81e8d88fe693e2efd770e2f08cc1be576bb3a46ddae543562c95c760e917f39f895ba64bb5e039fff6a68ea9e4eccb690194a8db
|
data/README.md
CHANGED
@@ -41,7 +41,7 @@ f.freeze
|
|
41
41
|
f.long_calc # => FrozenError, can't set `@long_calc`
|
42
42
|
```
|
43
43
|
|
44
|
-
Some techniques could include storing the cache in a mutable data
|
44
|
+
Some techniques could include storing the cache in a mutable data structure:
|
45
45
|
|
46
46
|
```ruby
|
47
47
|
class Foo
|
@@ -76,6 +76,8 @@ This gem will:
|
|
76
76
|
- not write to the cache,
|
77
77
|
- (or maybe use a separate Ractor / `SharedHash`)
|
78
78
|
|
79
|
+
Implementation details pexplained here](hacker_guide.md)
|
80
|
+
|
79
81
|
## Contributing
|
80
82
|
|
81
83
|
Bug reports and pull requests are welcome on GitHub at https://github.com/marcandre/ractor-cache. 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/marcandre/ractor-cache/blob/master/CODE_OF_CONDUCT.md).
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
class Ractor
|
4
4
|
module Cache
|
5
|
+
EMPTY_CACHE = Class.new.freeze # lazy way to get a name
|
6
|
+
|
5
7
|
module Strategy
|
6
8
|
class Base
|
7
9
|
attr_reader :parameters, :method_name
|
@@ -12,7 +14,8 @@ class Ractor
|
|
12
14
|
end
|
13
15
|
|
14
16
|
def compile_store_init
|
15
|
-
|
17
|
+
init = @has_arguments ? "Hash.new { #{EMPTY_CACHE} }" : EMPTY_CACHE
|
18
|
+
"@#{method_name} = #{init}"
|
16
19
|
end
|
17
20
|
|
18
21
|
private def analyse_parameters(parameters) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
@@ -53,7 +56,7 @@ class Ractor
|
|
53
56
|
class Prebuild < Base
|
54
57
|
def initialize(*)
|
55
58
|
super
|
56
|
-
raise "Can not cache method #{method_name} by prebuilding because it accepts arguments" if @has_arguments
|
59
|
+
raise ArgumentError, "Can not cache method #{method_name} by prebuilding because it accepts arguments" if @has_arguments
|
57
60
|
end
|
58
61
|
|
59
62
|
def deep_freeze_callback(instance)
|
@@ -63,7 +66,10 @@ class Ractor
|
|
63
66
|
def compile_accessor
|
64
67
|
<<~RUBY
|
65
68
|
def #{method_name}(#{signature})
|
66
|
-
ractor_cache.#{method_name}
|
69
|
+
r = ractor_cache.#{method_name}
|
70
|
+
return r unless r == EMPTY_CACHE
|
71
|
+
|
72
|
+
ractor_cache.#{method_name} = super
|
67
73
|
end
|
68
74
|
RUBY
|
69
75
|
end
|
@@ -73,11 +79,12 @@ class Ractor
|
|
73
79
|
def compile_accessor
|
74
80
|
<<~RUBY
|
75
81
|
def #{method_name}(#{signature})
|
76
|
-
ractor_cache.#{method_name}#{compile_lookup}
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
82
|
+
r = ractor_cache.#{method_name}#{compile_lookup}
|
83
|
+
return r unless r == EMPTY_CACHE
|
84
|
+
|
85
|
+
r = super
|
86
|
+
ractor_cache.#{method_name}#{compile_lookup} = r unless ractor_cache.frozen?
|
87
|
+
r
|
81
88
|
end
|
82
89
|
RUBY
|
83
90
|
end
|
@@ -104,7 +111,7 @@ class Ractor
|
|
104
111
|
) # => Strategy
|
105
112
|
self[strategy || :prebuild].new(to_cache)
|
106
113
|
rescue ArgumentError
|
107
|
-
return new(:
|
114
|
+
return new(:disable, to_cache: to_cache) if strategy == nil
|
108
115
|
|
109
116
|
raise
|
110
117
|
end
|
data/lib/ractor/cache/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ractor-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc-Andre Lafortune
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: require_relative_dir
|