Class: Dis::SparseLayer

Inherits:
Layer
  • Object
show all
Defined in:
lib/dis/sparse_layer.rb

Overview

Dis SparseLayer

A special case of Dis::Layer intended to be sparsely populated. Can be configured with a size limit, objects that have been transferred to other layers will be evicted based on a Least Recently Used basis.

Example

Dis::SparseLayer.new(
  Fog::Storage.new({
    provider: 'Local',
    local_root: Rails.root.join('db', 'dis')
  }),
  path: Rails.env,
  limit: 10.gigabytes
)

Instance Attribute Summary

Attributes inherited from Layer

#connection

Instance Method Summary collapse

Methods inherited from Layer

#delayed?, #exists?, #immediate?, #public?, #readonly?, #writeable?

Constructor Details

#initialize(connection, options = {}) ⇒ SparseLayer

Returns a new instance of SparseLayer.



21
22
23
24
# File 'lib/dis/sparse_layer.rb', line 21

def initialize(connection, options={})
  super
  @limit = options[:limit]
end

Instance Method Details

#delete(type, hash) ⇒ Object



42
43
44
45
46
# File 'lib/dis/sparse_layer.rb', line 42

def delete(type, hash)
  super.tap do
    delete_timestamp(type, hash)
  end
end

#get(type, hash) ⇒ Object



36
37
38
39
40
# File 'lib/dis/sparse_layer.rb', line 36

def get(type, hash)
  super.tap do |result|
    update_timestamp(type, hash) if result
  end
end

#limit?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/dis/sparse_layer.rb', line 26

def limit?
  @limit ? true : false
end

#store(type, hash, file) ⇒ Object



30
31
32
33
34
# File 'lib/dis/sparse_layer.rb', line 30

def store(type, hash, file)
  super.tap do
    update_timestamp(type, hash)
  end
end