Class: Dis::Storage
- Inherits:
-
Object
- Object
- Dis::Storage
- Defined in:
- lib/dis/storage.rb
Overview
Dis Storage
This is the interface for interacting with the storage layers.
All queries are scoped by object type, which will default to the table name of the model. Take care to use your own scope if you interact with the store directly, as models will purge expired content when they change.
Files are stored with a SHA1 digest of the file contents as the key. This ensures data is deduplicated per scope. Hash collisions will be silently ignored.
Layers should be added to Dis::Storage.layers. At least one writeable, non-delayed layer must exist.
Class Method Summary collapse
-
.delayed_delete(type, hash) ⇒ Object
Deletes content from all delayed layers.
-
.delayed_store(type, hash) ⇒ Object
Transfers files from immediate layers to all delayed layers.
-
.delete(type, hash) ⇒ Object
Deletes a file from all layers.
-
.exists?(type, hash) ⇒ Boolean
Returns true if the file exists in any layer.
-
.get(type, hash) ⇒ Object
Retrieves a file from the store.
-
.layers ⇒ Object
Exposes the layer set, which is an instance of
Dis::Layers. -
.store(type, file) ⇒ Object
Stores a file and returns a digest.
Class Method Details
.delayed_delete(type, hash) ⇒ Object
107 108 109 110 111 |
# File 'lib/dis/storage.rb', line 107 def delayed_delete(type, hash) layers.delayed.writeable.each do |layer| layer.delete(type, hash) end end |
.delayed_store(type, hash) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/dis/storage.rb', line 43 def delayed_store(type, hash) file = get(type, hash) layers.delayed.writeable.each do |layer| layer.store(type, hash, file) end end |
.delete(type, hash) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/dis/storage.rb', line 92 def delete(type, hash) require_writeable_layers! deleted = false layers.immediate.writeable.each do |layer| deleted = true if layer.delete(type, hash) end if layers.delayed.writeable.any? Dis::Jobs::Delete.perform_later(type, hash) end deleted end |
.exists?(type, hash) ⇒ Boolean
53 54 55 56 57 58 59 |
# File 'lib/dis/storage.rb', line 53 def exists?(type, hash) require_layers! layers.each do |layer| return true if layer.exists?(type, hash) end false end |
.get(type, hash) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/dis/storage.rb', line 69 def get(type, hash) require_layers! miss = false layers.each do |layer| if result = layer.get(type, hash) store_immediately!(type, result) if miss return result else miss = true end end raise Dis::Errors::NotFoundError end |
.layers ⇒ Object
Exposes the layer set, which is an instance of Dis::Layers.
22 23 24 |
# File 'lib/dis/storage.rb', line 22 def layers @layers ||= Dis::Layers.new end |