Salli
A Sinatra Dalli Gem for page, fragment and key value caching.
Installation
Add this line to your application's Gemfile:
gem 'salli'
And then execute:
$ bundle
Or install it yourself as:
$ gem install salli
Dependencies
This gem uses Dalli, a high performance memcached client for Ruby.
Getting started
If you're using a modern structure, you'll have to register Salli.
class CatsAreAwesome < Sinatra::Base
register Sinatra::Salli
get '/' do
erb :index
end
end
If you're using the classic structure, you'll just have to require it.
require "salli"
get '/' do
erb :index
end
Default settings
There are a few settings
# Default server
app.set :cache_server, 'localhost:11211'
# Cache on/off
app.set :cache, true
# Expiration (seconds)
app.set :cache_expires, 600
# Cache logging (development)
app.set :cache_logging, true
# Default cache environment
app.set :cache_environment, :development
Fragment caching
Fragment caching is fairly straight forward, you can also set a custom expiry.
<% cache 'bar', expires: 300 do %>
...
<% end %>
Key value caching
Store an item simple, there are 3 parameters: key, value & expires
cache_set(:key, 'your value', 300)
To retretive an item, you just specify the key:
cache_get(:key)
Delete cache
Delete an item by key:
cache_delete(:key)
Flush all cache:
cache_flush
License
MIT License