github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

kematzy / sinatra-cache

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 41
    • 7
  • Source
  • Commits
  • Network (7)
  • Issues (0)
  • Downloads (1)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (2)
    • master ✓
    • wip
  • Tags (1)
    • pre_0.9_version
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Page Caching for Sinatra — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Bumped the version to 0.2.2 
kematzy (author)
Sat Mar 14 02:14:31 -0700 2009
commit  92b60aab9915bbc790dafe7dec5c213adbd06f64
tree    f8dfa76662356ffb180e2eab02ca0e3a096662f1
parent  aeac879b45006573828bfbcbf49ee7c4d75a3e89
sinatra-cache /
name age
history
message
file .gitignore Loading commit data...
file LICENSE
file README.textile Sat Mar 14 02:13:50 -0700 2009 Updated the README with some further info and t... [kematzy]
file Rakefile Tue Feb 24 09:20:26 -0800 2009 Gemified the whole thing with Jeweler. First at... [kematzy]
file VERSION.yml Sat Mar 14 01:47:56 -0700 2009 Version bump to 0.2.2 [kematzy]
directory lib/ Sat Mar 14 02:10:03 -0700 2009 Put the <!-- page_cached_timestamp --> at the b... [kematzy]
file sinatra-cache.gemspec Sat Mar 14 02:14:31 -0700 2009 Bumped the version to 0.2.2 [kematzy]
directory test/ Sat Mar 14 02:10:03 -0700 2009 Put the <!-- page_cached_timestamp --> at the b... [kematzy]
README.textile

Sinatra::Cache

Adds a very simple Page Caching functionality to Sinatra


PLEASE KEEP THIS IN MIND

This is unfinished work, so use with care.

If you find it lacking or badly coded, please feel free to fork and improve. I’ll be very happy :)


TODO’s

= Make caching an option of the normal erb()/haml()/sass() methods, sort of like this:


  erb(:index, :cache => true/false)

  1. alternatively enable caching by setting a global config like this
    set :cache_enabled_for :all || :only/except => [‘/’,‘/contact’,…]

= Improve the logging output to the standard Sinatra output (if we are having :logging enabled )

= Add fragment caching…

= Enable the options functionality for the :cache & :cache_expire methods, so that they can take custom extensions and more


CONFIGURATION

Example 1: Sinatra ‘classic’ app.



require ‘sinatra/cache’

  1. toggle for the cache functionality.
    set :cache_enabled, true
  2. sets the default extension for cached files
    set :cache_page_extension, ‘.html’
  3. sets the Cache dir to the root of the /public directory.
    set :cache_output_dir, ’’ # was :cache_dir
    …

Example 2: Sinatra ‘sub-classed’ app.


  <snip....>
  require 'sinatra/cache'
  
  class MyApp < Sinatra::Base
    
    register Sinatra::Cache
    
    # toggle for the cache functionality.
    set :cache_enabled, true
    # sets the default extension for cached files
    set :cache_page_extension, '.html'
    # sets the Cache output dir to the root of the /public directory.
    set :cache_output_dir, '' # was :cache_dir
    
    <snip....>

USAGE

Basic Page Caching into static HTML files


  get '/contact' do
    # NB!  options is currently not working
    cache( erb( :contact ), :options => 'should go here' )
  end

Expiring old pages (ie: after POST or PUT events)


  # not very good example
  post '/contact' do
    cache_expire( '/contact', options )
  end

See the test and test/fixtures directories for more examples.


DEFAULT OPTIONS

  • :cache_enabled => toggle for the cache functionality. Default is: true
  • :cache_page_extension => sets the default extension for cached files. Default is: .html
  • :cache_output_dir => sets cache directory where cached files are stored. Default is: ‘’(empty) == root of /public.
    set to empty, since the ideal ’system/cache/’ does not currently work with Passenger & mod_rewrite :(
  • :cache_logging => toggle for logging the cache calls. Default is: true
  • :cache_logging_level => sets the level of the cache logger. Default is: :info.
    Options:(unused atm) [:info, :warn, :debug]

Credits

A big Thank You! goes to rtomayko, blakemizerany and others working on the Sinatra framework.

Inspired by code from Rails & Merb
and sinatra-mailer

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server