Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Drop-in page caching using nginx, lua, and memcached

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 bin
Octocat-spinner-32 lib
Octocat-spinner-32 nginx
Octocat-spinner-32 spec
Octocat-spinner-32 src
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rvmrc
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Guardfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Rakefile
Octocat-spinner-32 accelerator-1.0-1.rockspec
Octocat-spinner-32 accelerator.gemspec
Octocat-spinner-32 build

Nginx Accelerator

Drop-in page caching using nginx, lua, and memcached.


  • Listens to Cache-Control max-age header
  • The memcached key is the URI (easy to expire on demand)
  • Really, really fast


You'll need an nginx build with the following modules:

Configure nginx


Drop the following line in any location directive:

access_by_lua "require('accelerator').access()";

For example:

http {
  server {
    listen 8080;

    location = / {
      access_by_lua "require('accelerator').access()";

The TTL is based on Cache-Control: max-age, but defaults to 10 seconds.

To configure your memcached connection information:

access_by_lua "require('accelerator').access({ host='', port=11211 })";

Ruby client

Install gem

gem install accelerator


cache ="localhost:11211")
cache.set("/test", "body")
cache.expire("/test", 10)

Running specs

Install Lua and Moonscript

brew install lua
brew install luarocks
luarocks build

Add moonscript to your path:

export PATH=$PATH:/usr/local/lib/luarocks/bin/

Install nginx-accelerator rock via luarocks

git clone git://
cd nginx-accelerator
luarocks make

Install PCRE

brew update
brew install pcre

Install OpenResty (nginx)

curl -O
tar xzvf ngx_openresty-
cd ngx_openresty-

Get your PCRE version:

brew info pcre

Replace VERSION below with the PCRE version:

./configure --with-luajit --with-cc-opt="-I/usr/local/Cellar/pcre/VERSION/include" --with-ld-opt="-L/usr/local/Cellar/pcre/VERSION/lib" --prefix=~/OpenResty
make install

Start nginx

cd nginx-accelerator

Run specs

bundle install
bundle exec rspec spec
Something went wrong with that request. Please try again.