lib/scrivito/cache/chainable.rb in scrivito_sdk-1.0.0 vs lib/scrivito/cache/chainable.rb in scrivito_sdk-1.1.0.rc1
- old
+ new
@@ -9,16 +9,17 @@
internal_write(transformed_key, value)
end
value
end
- def write(key, value, expires_in = nil)
+ def write(key, value, expires_in: nil, persistent: true)
transformed_key = transform_key(key)
- if forward_write?(key, value, expires_in)
- next_store.write(transformed_key, value, expires_in)
+ if persistent && forward_write?(key, value, expires_in)
+ next_store.write(transformed_key, value, expires_in: expires_in)
end
- internal_write(transformed_key, value, expires_in)
+
+ internal_write(transformed_key, value, expires_in) if persistent || tentative?
end
def fetch(key, &block)
read(key) || block.call.tap { |value| write(key, value) }
end
@@ -32,18 +33,22 @@
next_store.clear if next_store
end
private
+ def tentative?
+ raise NotImplementedError
+ end
+
def next_store
raise NotImplementedError
end
def internal_read(key)
raise NotImplementedError
end
- def internal_write(key, value, expires_in = nil)
+ def internal_write(key, value, expires_in)
raise NotImplementedError
end
def transform_key(key)
key