Class: Persistent::StorageSQLite
- Inherits:
-
Object
- Object
- Persistent::StorageSQLite
- Defined in:
- lib/persistent-cache/storage/storage_sq_lite.rb
Constant Summary collapse
- DB_TABLE =
"key_value"- DB_TIMEOUT =
30000
Instance Attribute Summary collapse
-
#storage_details ⇒ Object
Returns the value of attribute storage_details.
-
#storage_handler ⇒ Object
Returns the value of attribute storage_handler.
Instance Method Summary collapse
- #clear ⇒ Object
- #delete_entry(serialized_key) ⇒ Object
-
#initialize(storage_details) ⇒ StorageSQLite
constructor
A new instance of StorageSQLite.
- #keys ⇒ Object
- #lookup_key(serialized_key) ⇒ Object
- #save_key_value_pair(serialized_key, serialized_value, timestamp = nil) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(storage_details) ⇒ StorageSQLite
Returns a new instance of StorageSQLite.
12 13 14 15 16 17 |
# File 'lib/persistent-cache/storage/storage_sq_lite.rb', line 12 def initialize(storage_details) raise ArgumentError.new("Storage details not provided") if storage_details.nil? or storage_details == "" @storage_details = storage_details @storage_handler = connect_to_database @storage_handler.busy_timeout = 30000 end |
Instance Attribute Details
#storage_details ⇒ Object
Returns the value of attribute storage_details.
9 10 11 |
# File 'lib/persistent-cache/storage/storage_sq_lite.rb', line 9 def storage_details @storage_details end |
#storage_handler ⇒ Object
Returns the value of attribute storage_handler.
10 11 12 |
# File 'lib/persistent-cache/storage/storage_sq_lite.rb', line 10 def storage_handler @storage_handler end |
Instance Method Details
#clear ⇒ Object
51 52 53 54 55 |
# File 'lib/persistent-cache/storage/storage_sq_lite.rb', line 51 def clear EH::retry!(:args => []) do @storage_handler.execute("DELETE FROM #{DB_TABLE}") end end |
#delete_entry(serialized_key) ⇒ Object
33 34 35 36 37 |
# File 'lib/persistent-cache/storage/storage_sq_lite.rb', line 33 def delete_entry(serialized_key) EH::retry!(:args => [serialized_key]) do @storage_handler.execute("DELETE FROM #{DB_TABLE} WHERE key=?", serialized_key) end end |
#keys ⇒ Object
45 46 47 48 49 |
# File 'lib/persistent-cache/storage/storage_sq_lite.rb', line 45 def keys EH::retry!(:args => []) do @storage_handler.execute("SELECT key FROM #{DB_TABLE}") end end |
#lookup_key(serialized_key) ⇒ Object
27 28 29 30 31 |
# File 'lib/persistent-cache/storage/storage_sq_lite.rb', line 27 def lookup_key(serialized_key) EH::retry!(:args => [serialized_key]) do @storage_handler.execute("SELECT value, timestamp FROM #{DB_TABLE} WHERE key=?", serialized_key) end end |
#save_key_value_pair(serialized_key, serialized_value, timestamp = nil) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/persistent-cache/storage/storage_sq_lite.rb', line 19 def save_key_value_pair(serialized_key, serialized_value, = nil) delete_entry(serialized_key) time_entry = .nil? ? Time.now.to_s : .to_s EH::retry!(:args => [serialized_key, serialized_value, time_entry]) do @storage_handler.execute("INSERT INTO #{DB_TABLE} (key, value, timestamp) VALUES(?, ?, ?)",serialized_key, serialized_value, time_entry) end end |
#size ⇒ Object
39 40 41 42 43 |
# File 'lib/persistent-cache/storage/storage_sq_lite.rb', line 39 def size EH::retry!(:args => []) do @storage_handler.execute("SELECT value FROM #{DB_TABLE}").size end end |