Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

warrenguy/sinatra-redis-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sinatra/redis-cache

A simple redis backed cache for Sinatra applications.

Installing

  • Add the gem to your Gemfile

    source 'https://rubygems.org'
    gem 'sinatra-redis-cache'
  • Require it in your app after including Sinatra

    require 'sinatra/redis-cache'

Using in your app

Use cache_do anywhere you want to cache the output of a block of code.

The following will be cached for 60 seconds with the key test-key.

cache_do('test-key', 60) do
  'do something here'
end

If there is an unexpired object in the cache with the same key, it will be returned. If not, the code will be executed, returned, and stored in the cache.

Configuration

Include the following block in your app after including sinatra/redis-cache to configure. Defaults are shown.

Sinatra::RedisCache::Config.config do
  redis_conn      Redis.new
  namespace       'sinatra_cache'
  default_expires 3600
  lock_timeout    5
  environments    [:production]
  logger          Logger.new(STDERR)
end

About

A simple redis backed cache for Sinatra

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages