evt-entity_cache 0.18.2.2 → 2.0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 838c6018a8001308f99a54902b70f8d37581419a385ff4536c111c9eb28f3ad4
4
- data.tar.gz: 237181829497f38436f2f2f83d272b9f2f24ef881c3233f4c099847ec3b8d9c0
3
+ metadata.gz: bcdf7aa3489308ed84b73822573806208b675aa88a696234b8a883c0eda03cc2
4
+ data.tar.gz: 04c895524f043e2092a4853a478ebfb61ba73de99f616fe564e975a0d36d1623
5
5
  SHA512:
6
- metadata.gz: cf745d63db2be88cef416973a44e77e003e5a427448206552e7b78d936387e4831c1af0b5eb1393c06b26b88b1022119d9d4821799ef7f6cb192964d8c7f489d
7
- data.tar.gz: db8262629ff5139f7714874ac75c509eab5cbb6dad50ff1e32f8eb9b22f639a1c8be6745f81f245af641b8b63dd661270cff10e625d01afb242380e496191d1d
6
+ metadata.gz: c54ed18483b733b23872f2237f6d694e6b9e7dc373b602a08b9166f827e48a0b29983f4c5c25aa9c52bd9098798138b3fcca22b32eee2924698727b751fbe541
7
+ data.tar.gz: e017489372a170d34d6d616daffa67a736847e537b425730a36c7601fa753dd3117ee3e580efb3d54ae7999efa8b09fc6ccb42aa618cdb8a86398533591cd5fe
@@ -7,6 +7,8 @@ require 'entity_cache/log'
7
7
 
8
8
  require 'entity_cache/defaults'
9
9
 
10
+ require 'entity_cache/subject'
11
+
10
12
  require 'entity_cache/record'
11
13
  require 'entity_cache/record/destructure'
12
14
  require 'entity_cache/record/log_text'
@@ -11,6 +11,8 @@ require 'entity_cache/controls/subject'
11
11
  require 'entity_cache/controls/time'
12
12
  require 'entity_cache/controls/version'
13
13
 
14
+ require 'entity_cache/controls/specifier'
15
+
14
16
  require 'entity_cache/controls/persist_interval'
15
17
 
16
18
  require 'entity_cache/controls/store/external'
@@ -19,3 +21,5 @@ require 'entity_cache/controls/store/external/not_implemented'
19
21
  require 'entity_cache/controls/store/external/write'
20
22
 
21
23
  require 'entity_cache/controls/store/internal'
24
+
25
+ require 'entity_cache/controls/entity_cache'
@@ -0,0 +1,11 @@
1
+ class EntityCache
2
+ module Controls
3
+ module EntityCache
4
+ def self.example(subject=nil, entity_class: nil, specifier: nil, random_specifier: nil)
5
+ subject ||= Subject.example(entity_class: entity_class, specifier: specifier, random: random_specifier)
6
+
7
+ ::EntityCache.new(subject)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -15,7 +15,7 @@ class EntityCache
15
15
  persisted_time ||= self.persisted_time
16
16
  end
17
17
 
18
- EntityCache::Record.new(
18
+ ::EntityCache::Record.new(
19
19
  id,
20
20
  entity,
21
21
  version,
@@ -0,0 +1,16 @@
1
+ class EntityCache
2
+ module Controls
3
+ module Specifier
4
+ def self.example(specifier: nil, random: nil)
5
+ specifier ||= 'SomeSpecifier'
6
+ random ||= false
7
+
8
+ if random
9
+ specifier = "#{specifier}#{SecureRandom.hex(8)}"
10
+ end
11
+
12
+ specifier
13
+ end
14
+ end
15
+ end
16
+ end
@@ -2,8 +2,10 @@ class EntityCache
2
2
  module Controls
3
3
  module Store
4
4
  module External
5
- def self.example(subject=nil)
6
- subject ||= Subject.example
5
+ def self.example(subject=nil, entity_class: nil, specifier: nil, random: nil)
6
+ random = true if random.nil?
7
+
8
+ subject ||= Subject.example(random: random, entity_class: entity_class, specifier: specifier)
7
9
 
8
10
  Example.build(subject)
9
11
  end
@@ -39,7 +39,9 @@ class EntityCache
39
39
  def self.path(subject, id=nil)
40
40
  id ||= ID.example
41
41
 
42
- File.join(tmpdir, "#{subject}-#{id}.yaml")
42
+ filename = "#{subject.to_s.gsub('/', '-')}-#{id}.yaml"
43
+
44
+ File.join(tmpdir, filename)
43
45
  end
44
46
 
45
47
  def self.tmpdir
@@ -1,8 +1,34 @@
1
1
  class EntityCache
2
2
  module Controls
3
3
  module Subject
4
- def self.example
5
- "some-subject-#{SecureRandom.hex(7)}"
4
+ def self.example(entity_class: nil, specifier: nil, random: nil)
5
+ entity_class ||= self.entity_class
6
+
7
+ if specifier == :none
8
+ specifier = nil
9
+ else
10
+ specifier = Specifier.example(specifier: specifier, random: random)
11
+ end
12
+
13
+ ::EntityCache::Subject.build({
14
+ :entity_class => entity_class,
15
+ :specifier => specifier
16
+ })
17
+ end
18
+
19
+ def self.entity_class
20
+ Entity::Example
21
+ end
22
+
23
+ def self.specifier
24
+ Specifier.example
25
+ end
26
+
27
+ module HashKey
28
+ def self.example(**args)
29
+ subject = Subject.example(**args)
30
+ subject.hash_key
31
+ end
6
32
  end
7
33
  end
8
34
  end
@@ -1,6 +1,7 @@
1
1
  class EntityCache
2
2
  include Configure
3
3
  include Dependency
4
+ include Initializer
4
5
  include Log::Dependency
5
6
 
6
7
  configure :entity_cache
@@ -10,12 +11,27 @@ class EntityCache
10
11
  @persist_interval ||= Defaults.persist_interval
11
12
  end
12
13
 
14
+ def entity_class
15
+ subject.entity_class
16
+ end
17
+
18
+ def specifier
19
+ subject.specifier
20
+ end
21
+
13
22
  dependency :clock, Clock::UTC
14
23
  dependency :internal_store, Store::Internal
15
24
  dependency :external_store, Store::External
16
25
 
17
- def self.build(subject, scope: nil, persist_interval: nil, external_store: nil, external_store_session: nil)
18
- instance = new
26
+ initializer :subject
27
+
28
+ def self.build(entity_class, specifier=nil, scope: nil, persist_interval: nil, external_store: nil, external_store_session: nil)
29
+ subject = Subject.build({
30
+ :entity_class => entity_class,
31
+ :specifier => specifier
32
+ })
33
+
34
+ instance = new(subject)
19
35
 
20
36
  instance.configure(
21
37
  subject: subject,
@@ -54,7 +70,7 @@ class EntityCache
54
70
  if record.nil?
55
71
  logger.info(tags: [:get, :miss]) { "Cache miss getting entity (ID: #{id.inspect}, #{Record::LogText.get(record)})" }
56
72
  else
57
- logger.info(tag: [:get, :hit]) { "Get entity done (ID: #{id.inspect}, #{Record::LogText.get(record)})" }
73
+ logger.info(tags: [:get, :hit]) { "Get entity done (ID: #{id.inspect}, #{Record::LogText.get(record)})" }
58
74
  end
59
75
 
60
76
  record
@@ -30,6 +30,14 @@ class EntityCache
30
30
  end
31
31
  end
32
32
 
33
+ def entity_class
34
+ subject.entity_class
35
+ end
36
+
37
+ def specifier
38
+ subject.specifier
39
+ end
40
+
33
41
  module Configure
34
42
  def configure(session: nil)
35
43
  ::Telemetry.configure(self)
@@ -0,0 +1,29 @@
1
+ class EntityCache
2
+ class Subject
3
+ include Schema::DataStructure
4
+
5
+ attribute :entity_class, Class
6
+ attribute :specifier, String
7
+
8
+ def hash_key
9
+ self.class.hash_key(entity_class, specifier)
10
+ end
11
+ alias_method :to_s, :hash_key
12
+
13
+ def hash
14
+ hash_key.hash
15
+ end
16
+
17
+ def self.hash_key(entity_class, specifier=nil)
18
+ if specifier.nil?
19
+ "#{entity_class}"
20
+ else
21
+ "#{entity_class}#{hash_key_separator}#{specifier}"
22
+ end
23
+ end
24
+
25
+ def self.hash_key_separator
26
+ '/'
27
+ end
28
+ end
29
+ end
@@ -5,6 +5,9 @@ class EntityCache
5
5
  end
6
6
 
7
7
  class EntityCache < EntityCache
8
+ def initialize
9
+ end
10
+
8
11
  def self.build
9
12
  new
10
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-entity_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.2.2
4
+ version: 2.0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-03 00:00:00.000000000 Z
11
+ date: 2020-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evt-configure
@@ -89,9 +89,11 @@ files:
89
89
  - lib/entity_cache.rb
90
90
  - lib/entity_cache/controls.rb
91
91
  - lib/entity_cache/controls/entity.rb
92
+ - lib/entity_cache/controls/entity_cache.rb
92
93
  - lib/entity_cache/controls/id.rb
93
94
  - lib/entity_cache/controls/persist_interval.rb
94
95
  - lib/entity_cache/controls/record.rb
96
+ - lib/entity_cache/controls/specifier.rb
95
97
  - lib/entity_cache/controls/store/external.rb
96
98
  - lib/entity_cache/controls/store/external/example.rb
97
99
  - lib/entity_cache/controls/store/external/not_implemented.rb
@@ -118,13 +120,13 @@ files:
118
120
  - lib/entity_cache/store/internal/scope/global.rb
119
121
  - lib/entity_cache/store/internal/scope/thread.rb
120
122
  - lib/entity_cache/store/internal/substitute.rb
123
+ - lib/entity_cache/subject.rb
121
124
  - lib/entity_cache/substitute.rb
122
- - lib/loader.rb
123
125
  homepage: https://github.com/eventide-project/entity-cache
124
126
  licenses:
125
127
  - MIT
126
128
  metadata: {}
127
- post_install_message:
129
+ post_install_message:
128
130
  rdoc_options: []
129
131
  require_paths:
130
132
  - lib
@@ -139,9 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
141
  - !ruby/object:Gem::Version
140
142
  version: '0'
141
143
  requirements: []
142
- rubyforge_project:
143
- rubygems_version: 2.7.3
144
- signing_key:
144
+ rubygems_version: 3.1.2
145
+ signing_key:
145
146
  specification_version: 4
146
147
  summary: Cache of entities retrieved by an entity-store, with in-memory temporary
147
148
  and on-disk permanent storage options
@@ -1 +0,0 @@
1
- lib/entity_cache.rb