Class: SolidCache::Entry
- Inherits:
-
Record
- Object
- ActiveRecord::Base
- Record
- SolidCache::Entry
show all
- Includes:
- Expiration
- Defined in:
- app/models/solid_cache/entry.rb,
app/models/solid_cache/entry/expiration.rb
Defined Under Namespace
Modules: Expiration
Constant Summary
collapse
- ID_BYTE_SIZE =
8
- CREATED_AT_BYTE_SIZE =
8
- KEY_HASH_BYTE_SIZE =
8
- VALUE_BYTE_SIZE =
4
- FIXED_SIZE_COLUMNS_BYTE_SIZE =
ID_BYTE_SIZE + CREATED_AT_BYTE_SIZE + KEY_HASH_BYTE_SIZE + VALUE_BYTE_SIZE
Constants inherited
from Record
Record::NULL_INSTRUMENTER
Class Method Summary
collapse
Methods inherited from Record
disable_instrumentation, with_shard
Class Method Details
.clear_delete ⇒ Object
48
49
50
|
# File 'app/models/solid_cache/entry.rb', line 48
def clear_delete
in_batches.delete_all
end
|
.clear_truncate ⇒ Object
44
45
46
|
# File 'app/models/solid_cache/entry.rb', line 44
def clear_truncate
connection.truncate(table_name)
end
|
.decrement(key, amount) ⇒ Object
63
64
65
|
# File 'app/models/solid_cache/entry.rb', line 63
def decrement(key, amount)
increment(key, -amount)
end
|
.delete_by_key(key) ⇒ Object
35
36
37
|
# File 'app/models/solid_cache/entry.rb', line 35
def delete_by_key(key)
delete_no_query_cache(lookup_column, lookup_value(key))
end
|
.delete_multi(keys) ⇒ Object
39
40
41
42
|
# File 'app/models/solid_cache/entry.rb', line 39
def delete_multi(keys)
serialized_keys = keys.map { |key| lookup_value(key) }
delete_no_query_cache(lookup_column, serialized_keys)
end
|
.increment(key, amount) ⇒ Object
52
53
54
55
56
57
58
59
60
61
|
# File 'app/models/solid_cache/entry.rb', line 52
def increment(key, amount)
transaction do
uncached do
result = lock.where(lookup_column => lookup_value(key)).pick(:key, :value)
amount += result[1].to_i if result&.first == key
write(key, amount)
amount
end
end
end
|
.read(key) ⇒ Object
24
25
26
27
|
# File 'app/models/solid_cache/entry.rb', line 24
def read(key)
result = select_all_no_query_cache(get_sql, lookup_value(key)).first
result[1] if result&.first == key
end
|
.read_multi(keys) ⇒ Object
29
30
31
32
33
|
# File 'app/models/solid_cache/entry.rb', line 29
def read_multi(keys)
key_hashes = keys.map { |key| lookup_value(key) }
results = select_all_no_query_cache(get_all_sql(key_hashes), key_hashes).to_h
results.except!(results.keys - keys)
end
|
.write(key, value) ⇒ Object
16
17
18
|
# File 'app/models/solid_cache/entry.rb', line 16
def write(key, value)
upsert_all_no_query_cache([ { key: key, value: value } ])
end
|
.write_multi(payloads) ⇒ Object
20
21
22
|
# File 'app/models/solid_cache/entry.rb', line 20
def write_multi(payloads)
upsert_all_no_query_cache(payloads)
end
|