Class: Dial::Storage
- Inherits:
-
Object
show all
- Defined in:
- lib/dial/storage.rb,
lib/dial/storage/file_adapter.rb,
lib/dial/storage/redis_adapter.rb,
lib/dial/storage/memcached_adapter.rb
Defined Under Namespace
Classes: FileAdapter, MemcachedAdapter, RedisAdapter
Constant Summary
collapse
- SUPPORTED_ADAPTERS =
[FileAdapter, RedisAdapter, MemcachedAdapter].freeze
Class Method Summary
collapse
Class Method Details
.adapter ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/dial/storage.rb', line 40
def adapter
return @adapter if @adapter
@mutex.synchronize do
@adapter ||= build_adapter
end
end
|
.cleanup ⇒ Object
60
61
62
|
# File 'lib/dial/storage.rb', line 60
def cleanup
adapter.cleanup if adapter.respond_to? :cleanup
end
|
.delete(key) ⇒ Object
56
57
58
|
# File 'lib/dial/storage.rb', line 56
def delete key
adapter.delete key
end
|
20
21
22
23
|
# File 'lib/dial/storage.rb', line 20
def key
validate_key! key
key.split(":", 2).first
end
|
.fetch(key) ⇒ Object
52
53
54
|
# File 'lib/dial/storage.rb', line 52
def fetch key
adapter.fetch key
end
|
Format key for Redis Cluster compatibility (hash tags)
26
27
28
29
30
|
# File 'lib/dial/storage.rb', line 26
def format_key key
uuid = key
suffix = key.split(":", 2).last
"{#{uuid}}:#{suffix}"
end
|
.generate_profile_key ⇒ Object
36
37
38
|
# File 'lib/dial/storage.rb', line 36
def generate_profile_key
"#{Util.uuid}_vernier"
end
|
.profile_storage_key(profile_key) ⇒ Object
32
33
34
|
# File 'lib/dial/storage.rb', line 32
def profile_storage_key profile_key
"#{profile_key}:profile"
end
|
.store(key, data, ttl: nil) ⇒ Object
48
49
50
|
# File 'lib/dial/storage.rb', line 48
def store key, data, ttl: nil
adapter.store key, data, ttl: ttl
end
|
.validate_key!(key) ⇒ Object
14
15
16
17
18
|
# File 'lib/dial/storage.rb', line 14
def validate_key! key
unless key.match?(/\A.+_vernier:.+\z/)
raise ArgumentError, "Invalid key format: #{key}. Expected format: '<uuid>_vernier:<suffix>'"
end
end
|