47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/sinatra/memcache.rb', line 47
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
|