Skip to content

czerasz/nginx-caching-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nginx Caching Example

Exercise used in my blog post.

Overview

The diagram below illustrates the docker environment used in this exercise:

docker-environment

Setup

Build the image:

./bin/build-container.sh

Start the container:

./bin/start-container.sh 

Removing Objects from Cache

Removing objects from the cache is called purging. In this example Nginx was build together with the Cache Purge Module which enables the purging functionality.

The instructions below will guide you through the process.

Save an object in the cache:

curl localhost:8080/test

Ensure that the request was cached:

$ docker diff nginx-cache-example | grep 'A /tmp/nginx/cache/a/da/'
A /tmp/nginx/cache/a/da/c3d3bae866df806718afd1153a9ffdaa

Purge from outside:

$ curl -XPURGE localhost:8080/test
<html>
<head><title>Successful purge</title></head>
<body bgcolor="white">
<center><h1>Successful purge</h1>
<br>Key : httplocalhost/test
<br>Path: /tmp/nginx/cache/a/da/c3d3bae866df806718afd1153a9ffdaa
</center>
<hr><center>nginx/1.6.2</center>
</body>
</html>

You can also purge from inside the container with this command:

docker exec nginx-cache-example curl -i localhost/purge/test

Requirements

Resources

About

Example code showing how Nginx caching works.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published