README 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. Rack::Cache
  2. ===========
  3. Rack::Cache is suitable as a quick drop-in component to enable HTTP caching for
  4. Rack-based applications that produce freshness (Expires, Cache-Control) and/or
  5. validation (Last-Modified, ETag) information:
  6. * Standards-based (RFC 2616)
  7. * Freshness/expiration based caching
  8. * Validation (If-Modified-Since / If-None-Match)
  9. * Vary support
  10. * Cache-Control: public, private, max-age, s-maxage, must-revalidate,
  11. and proxy-revalidate.
  12. * Portable: 100% Ruby / works with any Rack-enabled framework
  13. * Disk, memcached, and heap memory storage backends
  14. For more information about Rack::Cache features and usage, see:
  15. http://tomayko.com/src/rack-cache/
  16. Rack::Cache is not overly optimized for performance. The main goal of the
  17. project is to provide a portable, easy-to-configure, and standards-based
  18. caching solution for small to medium sized deployments. More sophisticated /
  19. high-performance caching systems (e.g., Varnish, Squid, httpd/mod-cache) may be
  20. more appropriate for large deployments with significant throughput requirements.
  21. Installation
  22. ------------
  23. From Gem:
  24. $ sudo gem install rack-cache
  25. With a local working copy:
  26. $ git clone git://github.com/rtomayko/rack-cache.git
  27. $ rake package && sudo rake install
  28. Basic Usage
  29. -----------
  30. Rack::Cache is implemented as a piece of Rack middleware and can be used with
  31. any Rack-based application. If your application includes a rackup (`.ru`) file
  32. or uses Rack::Builder to construct the application pipeline, simply require
  33. and use as follows:
  34. require 'rack/cache'
  35. use Rack::Cache,
  36. :metastore => 'file:/var/cache/rack/meta',
  37. :entitystore => 'file:/var/cache/rack/body',
  38. :verbose => true
  39. run app
  40. Assuming you've designed your backend application to take advantage of HTTP's
  41. caching features, no further code or configuration is required for basic
  42. caching.
  43. Using with Rails
  44. ----------------
  45. Add this to your `config/environment.rb`:
  46. config.middleware.use Rack::Cache,
  47. :verbose => true,
  48. :metastore => 'file:/var/cache/rack/meta',
  49. :entitystore => 'file:/var/cache/rack/body'
  50. You should now see `Rack::Cache` listed in the middleware pipeline:
  51. rake middleware
  52. See the following for more information:
  53. http://snippets.aktagon.com/snippets/302
  54. Using with Dalli
  55. ----------------
  56. Dalli is a high performance memcached client for Ruby.
  57. More information at: https://github.com/mperham/dalli
  58. require 'dalli'
  59. require 'rack/cache'
  60. use Rack::Cache,
  61. :verbose => true,
  62. :metastore => "memcached://localhost:11211/meta",
  63. :entitystore => "memcached://localhost:11211/body"
  64. run app
  65. Links
  66. -----
  67. Documentation:
  68. http://tomayko.com/src/rack-cache/
  69. Mailing List:
  70. http://groups.google.com/group/rack-cache
  71. GitHub:
  72. http://github.com/rtomayko/rack-cache/
  73. License
  74. -------
  75. Copyright (c) 2008 Ryan Tomayko <http://tomayko.com/about>
  76. Permission is hereby granted, free of charge, to any person obtaining a copy
  77. of this software and associated documentation files (the "Software"), to
  78. deal in the Software without restriction, including without limitation the
  79. rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  80. sell copies of the Software, and to permit persons to whom the Software is
  81. furnished to do so, subject to the following conditions:
  82. The above copyright notice and this permission notice shall be included in
  83. all copies or substantial portions of the Software.
  84. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  85. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  86. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  87. THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  88. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  89. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.