Coder Social home page Coder Social logo

boniface / php-redis-controller Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mrboson/php-redis-controller

0.0 2.0 0.0 60 KB

This cache controller is an observer that interfaces with a Redis server. It will check to see if a request is eligible for caching, and if so, determine if a cached copy is available.

License: The Unlicense

php-redis-controller's Introduction

php-redis-controller

This cache controller is an observer that interfaces with a Redis server. It will check to see if a request is eligible for caching, and if so, determine if a cached copy is available. When available, the cached copy is returned to the browser, including all http headers. When not available, your PHP code will function as normal to generate content. The controller will cache that content to be available on the next request.

The basic purpose of this php-redis-controller is to provide a lightweight (and easy to implement) front end cache to any PHP page you wish to make cacheable. I use this in front of my Wordpress installs, and I generally get millisecond rendering times for pages that get cached.

Requirements

Php-redis-controller depends on the PhpRedis extension provided by Nicolasff (available at https://github.com/nicolasff/phpredis). Follow the instructions there to acquire and install the extension.

Implementation

Include redis_cache_controller/loader.php on any PHP page you wish to be managed by the cache controller. Change the constants and config variables at the top of loader.php to match your environment.

Test using the provided sample.php.

Cache Sets and Flushing

Php-redis-controller allows you to define sets or collections of caches. While each page in cache is tracked individually, each is also tracked according to which set it belongs to. This makes it possible to delete all of the pages in a set at once. For example, I use this in a Wordpress system to flush all cache entries associated with a blog post every time the post is edited or receives a comment. Flushing can be triggered by two special directives that can be appended to a URL in order to flush items out of the cache. Usage: http://mysite.com/mypage.php?_r=flush -- this will flush mypage.php out of the cache http://mysite.com/mypage.php?_r=flushall -- this will flush all pages belonging to mypage.php's cache set.

Integration with your site

Assuming your Redis server is running and avaliable via the PhpRedis extension on your server, the php-redis-controller will begin caching and serving from cache automatically.

There are some behaviors you can control, such as disabling caching for for pages based on querystring arguments, path segments, and cookies. See loader.php for an example.

You (or your PHP code) can also embed special tokens into the content which will be evaluated by the cache controller. See the example in sample.php.

WordPress Integration

Take a look at the wordpress-sample.php file. Basically, you want to use something like this instead of the normal index.php used by WordPress (i.e., you could change which file is the default index in your WordPress root). You will also want to copy the file in the WordPress-plugin into your WP plugins folder, then in wp-admin activate the RCC Functions plugin.

php-redis-controller's People

Contributors

mrboson avatar

Watchers

Boniface Kabaso avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.