项目作者: clickalicious

项目描述 :
The PSR-7 middleware for caching compatible to PSR-6.
高级语言: PHP
项目地址: git://github.com/clickalicious/caching-middleware.git
创建时间: 2015-10-08T09:32:58Z
项目社区:https://github.com/clickalicious/caching-middleware

开源协议:MIT License

下载



Logo of Caching-Middleware

The PSR-7 middleware for caching compatible to PSR-6.

Build Status Codacy grade Codacy coverage clickalicious open source
GitHub release license Issue Stats Dependency Status

Table of Contents

Features

  • Caching of almost any content produced in a PHP execution loop like PHP, HTML (…)
  • Stackable into PSR-7 stacks for easy integration
  • Compatible to all PSR-6 caching implementations and a lot of caching backends
  • High performance (developed using a profiler)
  • Lightweight and high-quality codebase (following PSR-1,2,4,7)
  • 100% PSR-7 middleware compatibility
  • 100% PSR-6 caching compatibility
  • Clean & well documented code
  • Unit-tested with a good coverage

Example

This is just a simple demonstration on how to get started using this middleware library in a very simple context. Put a Cache in queue and use a PSR-6 Cache (Filesystem as backend - but you could also use Redis, Memcached, MySQL or any other backend implemented a PSR-6 caching layer …):

  1. /**
  2. * Fill queue for running "Caching Middleware"
  3. *
  4. * @param \Psr\Http\Message\ServerRequestInterface $request Request (PSR) to process
  5. * @param \Psr\Http\Message\ResponseInterface $response Response (PSR) to use
  6. * @param callable $next Next middleware in stack
  7. *
  8. * @return \Psr\Http\Message\ResponseInterface A PSR compatible response
  9. */
  10. $queue[] = function (Request $request, Response $response, callable $next) {
  11. // Create cache item factory
  12. $cacheItemFactory = function ($key) {
  13. return new CacheItem($key);
  14. };
  15. // Create cache item key factory
  16. $cacheItemKeyFactory = function (Request $request) {
  17. static $key = null;
  18. if (null === $key) {
  19. $uri = $request->getUri();
  20. $slugify = new Slugify();
  21. $key = $slugify->slugify(trim($uri->getPath(), '/').($uri->getQuery() ? '?'.$uri->getQuery() : ''));
  22. }
  23. return $key;
  24. };
  25. // Get cache
  26. $cachingMiddleWare = new Clickalicious\Caching\Middleware\Cache(
  27. new CacheItemPool('Filesystem'),
  28. $cacheItemFactory,
  29. $cacheItemKeyFactory
  30. );
  31. return $cachingMiddleWare($request, $response, $next);
  32. };

Requirements

  • PHP >= 5.6 (compatible up to version 7.2 as well as HHVM)

Philosophy

Caching Middleware is a PSR-7 compatible middleware based on PSR-6 compatible cache implementations. Caching Middleware isn’t a unicorn - it’s good but it maybe going to change with time. Try it, run it … ♥ it ;)

Versioning

For a consistent versioning we decided to make use of Semantic Versioning 2.0.0 http://semver.org. Its easy to understand, very common and known from many other software projects.

Roadmap

  • Cache whole response instead just rendered HTML (Headers as well for example)
  • Implement flysystem as Driver for PSR-Cache

Throughput Graph

Security Issues

If you encounter a (potential) security issue don’t hesitate to get in contact with us opensource@clickalicious.de before releasing it to the public. So i get a chance to prepare and release an update before the issue is getting shared. Thank you!

Participate & Share

… yeah. If you’re a code monkey too - maybe we can build a force ;) If you would like to participate in either Code, Comments, Documentation, Wiki, Bug-Reports, Unit-Tests, Bug-Fixes, Feedback and/or Critic then please let us know as well!


Sponsors

Thanks to our sponsors and supporters:

JetBrains Navicat
Icons made by Prosymbols from www.flaticon.com is licensed by CC 3.0 BY