cache.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. require 'rack'
  2. # = HTTP Caching For Rack
  3. #
  4. # Rack::Cache is suitable as a quick, drop-in component to enable HTTP caching
  5. # for Rack-enabled applications that produce freshness (+Expires+, +Cache-Control+)
  6. # and/or validation (+Last-Modified+, +ETag+) information.
  7. #
  8. # * Standards-based (RFC 2616 compliance)
  9. # * Freshness/expiration based caching and validation
  10. # * Supports HTTP Vary
  11. # * Portable: 100% Ruby / works with any Rack-enabled framework
  12. # * Disk, memcached, and heap memory storage backends
  13. #
  14. # === Usage
  15. #
  16. # Create with default options:
  17. # require 'rack/cache'
  18. # Rack::Cache.new(app, :verbose => true, :entitystore => 'file:cache')
  19. #
  20. # Within a rackup file (or with Rack::Builder):
  21. # require 'rack/cache'
  22. # use Rack::Cache do
  23. # set :verbose, true
  24. # set :metastore, 'memcached://localhost:11211/meta'
  25. # set :entitystore, 'file:/var/cache/rack'
  26. # end
  27. # run app
  28. module Rack::Cache
  29. autoload :Request, 'rack/cache/request'
  30. autoload :Response, 'rack/cache/response'
  31. autoload :Context, 'rack/cache/context'
  32. autoload :Storage, 'rack/cache/storage'
  33. autoload :CacheControl, 'rack/cache/cachecontrol'
  34. # Create a new Rack::Cache middleware component that fetches resources from
  35. # the specified backend application. The +options+ Hash can be used to
  36. # specify default configuration values (see attributes defined in
  37. # Rack::Cache::Options for possible key/values). When a block is given, it
  38. # is executed within the context of the newly create Rack::Cache::Context
  39. # object.
  40. def self.new(backend, options={}, &b)
  41. Context.new(backend, options, &b)
  42. end
  43. end