Class: Arango::Cache
- Inherits:
-
Object
- Object
- Arango::Cache
- Defined in:
- lib/Cache.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
Instance Method Summary collapse
- #clear ⇒ Object
- #destroy(type, id) ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
- #save(type, id, obj) ⇒ Object
- #to_h ⇒ Object
- #updateMax(type:, val:) ⇒ Object
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/Cache.rb', line 3 def initialize @max = { database: 10, collection: 20, document: 200, graph: 10, index: 20, user: 20, task: 20, view: 20, foxx: 20 } @cache = { database: {}, collection: {}, document: {}, graph: {}, index: {}, aql: {}, user: {}, task: {}, view: {}, foxx: {} } end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
30 31 32 |
# File 'lib/Cache.rb', line 30 def cache @cache end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
30 31 32 |
# File 'lib/Cache.rb', line 30 def max @max end |
Instance Method Details
#clear ⇒ Object
55 56 57 |
# File 'lib/Cache.rb', line 55 def clear @cache.each_key{|k| @cache[k] = {}} end |
#destroy(type, id) ⇒ Object
51 52 53 |
# File 'lib/Cache.rb', line 51 def destroy(type, id) @cache[type].delete(id) end |
#save(type, id, obj) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/Cache.rb', line 44 def save(type, id, obj) while @cache[type].length >= @max[type] @cache[type].shift end @cache[type][id] = obj end |
#to_h ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/Cache.rb', line 32 def to_h hash = { "max": @max, "cache": {} } @cache.each do |key, hash2| next if hash2.empty? hash[:cache][key] = hash2.keys end hash end |
#updateMax(type:, val:) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/Cache.rb', line 59 def updateMax(type:, val:) type = type.to_sym rescue type = :error unless @max.has_key?(type.to_sym) ArangoDB::Error.new :element_in_cache_does_not_exist, {wrong_attribute: :type, wrong_value: type} end while @cache[type].length > val @cache[type].shift end @max[type] = val end |