ismasan (owner)

Revisions

gist: 151406 Download_button fork
public
Public Clone URL: git://gist.github.com/151406.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Free RESTful interface for your Ruby objects with Rackable
# http://github.com/madx/rackable/tree/master
#
# + Free HTTP caching with rack-cache
# http://github.com/rtomayko/rack-cache/tree/master
 
require 'rackable'
require 'rack/cache'
 
APP_ROOT = File.dirname(__FILE__)
 
use Rack::Cache,
      :metastore => "file:#{APP_ROOT}/cache/rack/meta",
      :entitystore => "file:#{APP_ROOT}/cache/rack/body",
      :verbose => true
 
 
 
# Your app
#
class App
  include Rackable
  
  def get
    cache_long # makes Rack-cache kick in
    # just list some files
    Dir['./*'].inspect
  end
  
  private
  
  def cache_long
    rack.header['Cache-Control'] = 'public, max-age=3600'
    rack.header['Etag'] = object_id.to_s
  end
end
 
# Save as app.ru and run with:
#
# rackup -p 4000 app.ru
#
run App.new