Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delete from cache functionality of Specific URL #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

underscore05
Copy link

No description provided.

@thoop
Copy link

thoop commented Aug 29, 2018

It looks like this will just continue on with the normal routes, render the URL again, and then save the resulting HTML back into the redis cache since pageLoaded doesn't check for the req.method again. So in effect this is more like a recache instead of a delete. Is that intended?

This would be handy but I don't know if you'd actually want to expose this since anyone can send that DELETE request. Ideally you'd have a separate way of deleting pages from your cache that doesn't involve hitting the URL through your server.

@underscore05
Copy link
Author

I think it will not continue because of the following line.

        //
        if (req.method !== 'GET' || !redisOnline) {
            return next();
        }

And maybe a header with secret-token will suffice securing that delete functionality? Though, I don't know how to do that either.

@thoop
Copy link

thoop commented Aug 30, 2018

The next() there just means it would skip over the section of code that would return a page from the redis cache. Calling next() will let the Prerender server render the page, which then calls the pageLoaded event and, in this case, saves the content back into the redis cache. So right now you can use a POST request to recache the page by skipping redis, rendering the URL, and then saving the result into redis. The code you added just deletes the page from redis before it gets recached and saved back into redis.

For example, the code already in that file will try to find the result from redis, and if found, return the html using res.send(). If the response is not cached in redis, it will call next() so that the Prerender server can render the page and save it into the redis cache:

client.get(req.prerender.url, function (error, result) {
  if (!error && result) {
    var response = JSON.parse(result);
    var headers = response.headers;
    var key;

    for (key in headers) {
      if (headers.hasOwnProperty(key)) {
        res.setHeader(key, headers[key]);
      }
    }
    res.send(response.statusCode, response.content);
  } else {
    next();
  }
});

@underscore05
Copy link
Author

Hmm... does it mean that POST request will still called by prerenderer and be stored to cache if it returns a 200 status?

@underscore05
Copy link
Author

So right now you can use a POST request to recache the page by skipping redis, rendering the URL, and then saving the result into redis. 

ohhhh......

@JonathanBennett
Copy link
Owner

I have actually gone ahead and implemented this as it's heavily requested, and would leave it up to the responsibility of the proxy that (hopefully) exposes prerender to block this from external calls if this is undesirable.

@thoop I'd appreciate the feedback, so if you think this isn't the right approach, do let me know.

At the moment it sits on branch v0.3.0, and will await a bit of feedback before it's merged and released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants