public
Created

Purge a varnish cache from ghost patch :)

  • Download Gist
default.vcl
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
 
# Varnish VCL file for Ghost blogging platform.
# http://ghost.org/
#
# Written for Ghost v0.3.0.
 
 
backend default {
.host = "blog-jniedbalski.rhcloud.com";
.port = "80";
}
 
 
sub vcl_recv {
 
if (req.request == "PURGE") {
return (lookup);
}
 
set req.http.host = "blog-jniedbalski.rhcloud.com";
set req.http.x-pass = "false";
 
if (req.url ~ "^/(api|signout)") {
set req.http.x-pass = "true";
} elseif (req.url ~ "^/ghost" && (req.url !~ "^/ghost/(img|css|fonts)")) {
set req.http.x-pass = "true";
}
 
if (req.http.x-pass == "true") {
return(pass);
}
unset req.http.cookie;
}
 
sub vcl_hit {
if (req.request == "PURGE") {
ban("req.url == " + req.url);
error 200 "Purged.";
}
}
 
sub vcl_miss {
if (req.request == "PURGE") {
ban("req.url == " + req.url);
error 200 "Purged.";
}
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
 
sub vcl_fetch {
# Only modify cookies/ttl outside of the management interface.
if (req.http.x-pass != "true") {
unset beresp.http.set-cookie;
if (beresp.status < 500 && beresp.ttl == 0s) {
set beresp.ttl = 1w;
set beresp.http.X-Cacheable = "YES";
}
}
}
purge-varnish-ghost.patch
Diff
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
diff --git a/a b/a
new file mode 100644
index 0000000..e69de29
diff --git a/core/server/api.js b/core/server/api.js
index 3c7270e..fd7f7bb 100644
--- a/core/server/api.js
+++ b/core/server/api.js
@@ -4,6 +4,7 @@
var Ghost = require('../ghost'),
_ = require('underscore'),
when = require('when'),
+ request = require('request'),
errors = require('./errorHandling'),
permissions = require('./permissions'),
canThis = permissions.canThis,
@@ -62,8 +63,18 @@ posts = {
});
},
- // #### Edit
+ varnishPurge: function remove(url) {
+ var urls = [ '/' + url, '/' ];
+
+ for(i = 0; i < urls.length; i++) {
+ request({
+ method: 'PURGE',
+ uri: "http://www.metaklass.org" + urls[i]
+ });
+ }
+ },
+ // #### Edit
// **takes:** a json object with all the properties which should be updated
edit: function edit(postData) {
// **returns:** a promise for the resulting post in a json object
@@ -72,7 +83,9 @@ posts = {
}
return canThis(this.user).edit.post(postData.id).then(function () {
- return dataProvider.Post.edit(postData);
+ post = dataProvider.Post.edit(postData);
+ posts.varnishPurge(postData.slug);
+ return post;
}, function () {
return when.reject("You do not have permission to edit this post.");
});
@@ -88,7 +101,9 @@ posts = {
}
return canThis(this.user).create.post().then(function () {
- return dataProvider.Post.add(postData);
+ post = dataProvider.Post.add(postData);
+ posts.varnishPurge(postData.slug);
+ return post;
}, function () {
return when.reject("You do not have permission to add posts.");
});
@@ -106,6 +121,7 @@ posts = {
return canThis(this.user).remove.post(args.id).then(function () {
return when(posts.read({id : args.id})).then(function (result) {
return dataProvider.Post.destroy(args.id).then(function () {
+ posts.varnishPurge(result.slug);
var deletedObj = {};
deletedObj.id = result.id;
deletedObj.slug = result.slug;
diff --git a/package.json b/package.json
index 7233705..8f9613c 100644
--- a/package.json
+++ b/package.json
@@ -18,6 +18,7 @@
"underscore": "1.5.1",
"showdown": "0.3.1",
"sqlite3": "2.1.16",
+ "request": "latest",
"bookshelf": "0.5.7",
"knex": "0.4.11",
"when": "2.2.1",
diff --git a/test b/test
new file mode 100644
index 0000000..e69de29

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.