evt-entity_cache 0.13.0.0 → 0.14.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/entity_cache.rb +17 -15
  3. data/lib/entity_cache/controls.rb +12 -3
  4. data/lib/entity_cache/controls/entity.rb +27 -1
  5. data/lib/entity_cache/controls/persist_interval.rb +2 -22
  6. data/lib/entity_cache/controls/record.rb +33 -12
  7. data/lib/entity_cache/controls/storage/persistent.rb +8 -26
  8. data/lib/entity_cache/controls/storage/persistent/example.rb +41 -0
  9. data/lib/entity_cache/controls/storage/persistent/not_implemented.rb +19 -0
  10. data/lib/entity_cache/controls/storage/persistent/write.rb +25 -0
  11. data/lib/entity_cache/controls/storage/temporary.rb +14 -2
  12. data/lib/entity_cache/controls/subject.rb +2 -4
  13. data/lib/entity_cache/controls/time.rb +1 -12
  14. data/lib/entity_cache/controls/version.rb +5 -11
  15. data/lib/entity_cache/defaults.rb +2 -2
  16. data/lib/entity_cache/record.rb +36 -30
  17. data/lib/entity_cache/record/destructure.rb +29 -0
  18. data/lib/entity_cache/record/log_text.rb +9 -0
  19. data/lib/entity_cache/record/transformer.rb +26 -0
  20. data/lib/entity_cache/store/persistent/null.rb +15 -0
  21. data/lib/entity_cache/store/persistent/substitute.rb +64 -0
  22. data/lib/entity_cache/store/persistent/telemetry.rb +16 -0
  23. data/lib/entity_cache/store/temporary.rb +47 -0
  24. data/lib/entity_cache/store/temporary/build.rb +48 -0
  25. data/lib/entity_cache/store/temporary/build/defaults.rb +28 -0
  26. data/lib/entity_cache/{storage → store}/temporary/scope/exclusive.rb +1 -1
  27. data/lib/entity_cache/store/temporary/scope/global.rb +34 -0
  28. data/lib/entity_cache/store/temporary/scope/thread.rb +35 -0
  29. data/lib/entity_cache/store/temporary/substitute.rb +36 -0
  30. data/lib/entity_cache/substitute.rb +33 -17
  31. metadata +20 -58
  32. data/lib/entity_cache/entity_cache.rb +0 -83
  33. data/lib/entity_cache/error.rb +0 -3
  34. data/lib/entity_cache/storage/persistent.rb +0 -81
  35. data/lib/entity_cache/storage/persistent/none.rb +0 -15
  36. data/lib/entity_cache/storage/persistent/substitute.rb +0 -51
  37. data/lib/entity_cache/storage/persistent/telemetry.rb +0 -38
  38. data/lib/entity_cache/storage/temporary.rb +0 -56
  39. data/lib/entity_cache/storage/temporary/build.rb +0 -42
  40. data/lib/entity_cache/storage/temporary/scope/defaults.rb +0 -32
  41. data/lib/entity_cache/storage/temporary/scope/error.rb +0 -9
  42. data/lib/entity_cache/storage/temporary/scope/shared.rb +0 -31
@@ -1,38 +0,0 @@
1
- class EntityCache
2
- module Storage
3
- module Persistent
4
- module Telemetry
5
- def self.sink
6
- Sink.new
7
- end
8
-
9
- Data = Struct.new :id, :entity, :version, :time
10
-
11
- class Sink
12
- include ::Telemetry::Sink
13
-
14
- record :get
15
- record :put
16
-
17
- def retrieved?(&blk)
18
- return get_records if blk.nil?
19
-
20
- recorded_get? do |record|
21
- data = record.data
22
- blk.call(data.id, data.entity, data.version, data.time)
23
- end
24
- end
25
-
26
- def stored?(&blk)
27
- return put_records if blk.nil?
28
-
29
- recorded_put? do |record|
30
- data = record.data
31
- blk.call(data.id, data.entity, data.version, data.time)
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
38
- end
@@ -1,56 +0,0 @@
1
- class EntityCache
2
- module Storage
3
- class Temporary
4
- include Log::Dependency
5
-
6
- attr_reader :subject
7
-
8
- def initialize(subject)
9
- @subject = subject
10
- end
11
-
12
- def self.build(subject)
13
- instance = new subject
14
- instance
15
- end
16
-
17
- def self.configure(receiver, subject, scope: nil, attr_name: nil)
18
- attr_name ||= :temporary_store
19
-
20
- instance = Build.(subject, scope: scope)
21
- receiver.public_send "#{attr_name}=", instance
22
- instance
23
- end
24
-
25
- def get(id)
26
- records[id]
27
- end
28
-
29
- def put(record)
30
- records[record.id] = record
31
- end
32
-
33
- abstract :records
34
-
35
- module Assertions
36
- def empty?
37
- records.empty?
38
- end
39
-
40
- def put?(&block)
41
- block ||= proc { true }
42
-
43
- records.any? do |_, record|
44
- block.(record)
45
- end
46
- end
47
- end
48
-
49
- module Substitute
50
- def self.build
51
- Scope::Exclusive.build :substitute
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,42 +0,0 @@
1
- class EntityCache
2
- module Storage
3
- class Temporary
4
- module Build
5
- def self.call(subject, scope: nil)
6
- scope ||= Scope::Defaults.name
7
-
8
- scope_class = self.scope_class scope
9
-
10
- scope_class.build subject
11
- end
12
-
13
- def self.scope_class(scope_name)
14
- scope_class = scopes[scope_name]
15
-
16
- if scope_class.nil?
17
- *scopes, final_scope = self.scopes.keys
18
- scopes = "#{scopes * ', '} or #{scope_name}"
19
-
20
- error_message = %{Scope "#{scope_name}" is unknown. It must be one of: #{scopes}}
21
-
22
- logger.error error_message
23
- raise Scope::Error, error_message
24
- end
25
-
26
- scope_class
27
- end
28
-
29
- def self.scopes
30
- @scopes ||= {
31
- :exclusive => Scope::Exclusive,
32
- :shared => Scope::Shared
33
- }
34
- end
35
-
36
- def self.logger
37
- @logger ||= Log.get(self)
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,32 +0,0 @@
1
- class EntityCache
2
- module Storage
3
- class Temporary
4
- module Scope
5
- module Defaults
6
- def self.name
7
- Name.get
8
- end
9
-
10
- module Name
11
- def self.get
12
- value = env_var_value || self.value
13
- value.to_sym
14
- end
15
-
16
- def self.env_var_value
17
- ENV[env_var_name]
18
- end
19
-
20
- def self.env_var_name
21
- 'ENTITY_CACHE_SCOPE'
22
- end
23
-
24
- def self.value
25
- 'shared'
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,9 +0,0 @@
1
- class EntityCache
2
- module Storage
3
- class Temporary
4
- module Scope
5
- Error = Class.new(StandardError)
6
- end
7
- end
8
- end
9
- end
@@ -1,31 +0,0 @@
1
- class EntityCache
2
- module Storage
3
- class Temporary
4
- module Scope
5
- class Shared < Temporary
6
- def records
7
- subject_registry[subject] ||= {}
8
- end
9
-
10
- def subject_registry
11
- current_thread = Thread.current
12
-
13
- if current_thread.thread_variable?(thread_local_variable)
14
- subject_registry = current_thread.thread_variable_get(thread_local_variable)
15
- else
16
- subject_registry = {}
17
-
18
- current_thread.thread_variable_set(thread_local_variable, subject_registry)
19
- end
20
-
21
- subject_registry
22
- end
23
-
24
- def thread_local_variable
25
- :entity_cache_subject_registry
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end