14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/sinatra/dalli.rb', line 14
def cache(key, params = {}, &block)
return block.call unless settings.cache_enable
opts = {
:expiry => settings.cache_default_expiry,
:compress => settings.cache_default_compress
}.merge(params)
value = get(key, opts)
return value unless block_given?
if value
log "Get: #{key}"
value
else
log "Set: #{key}"
set(key, block.call, opts)
end
rescue => e
throw e if settings.development? || settings.show_exceptions
block.call
end
|