Download the PHP package asm89/twig-cache-extension without Composer

On this page you can find all versions of the php package asm89/twig-cache-extension. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package twig-cache-extension

Twig cache extension

This extension moved to the Twig organization. Check out the repository over there instead: https://github.com/twigphp/twig-cache-extension.

The missing cache extension for Twig. The extension allows for caching rendered parts of templates using several cache strategies.

Build Status

Installation

The extension is installable via composer:

Quick start

Setup

A minimal setup for adding the extension with the LifeTimeCacheStrategy and doctrine array cache is as following:

Want to use a PSR-6 cache pool?

Instead of using the default DoctrineCacheAdapter the extension also has a PSR-6 compatible adapter. You need to instantiate one of the cache pool implementations as can be found on: http://php-cache.readthedocs.io/en/latest/

Example: Making use of the ApcuCachePool via the PsrCacheAdapter:

Usage

To cache a part of a template in Twig surround the code with a cache block. The cache block takes two parameters, first an "annotation" part, second the "value" the cache strategy can work with. Example:

Cache blocks can be nested:

The annotation can also be an expression:

Cache strategies

The extension ships with a few cache strategies out of the box. Setup and usage of all of them is described below.

Lifetime

See the "Quick start" for usage information of the LifetimeCacheStrategy.

Generational

Strategy for generational caching.

In theory the strategy only saves fragments to the cache with infinite lifetime. The key of the strategy lies in the fact that the keys for blocks will change as the value for which the key is generated changes.

For example: entities containing a last update time, would include a timestamp in the key. For an interesting blog post about this type of caching see: http://37signals.com/svn/posts/3113-how-key-based-cache-expiration-works

Blackhole

Strategy for development mode.

In development mode it often not very useful to cache fragments. The blackhole strategy provides an easy way to not cache anything it all. It always generates a new key and does not fetch or save any fragments.

Setup

In order to use the strategy you need to setup a KeyGenerator class that is able to generate a cache key for a given value.

The following naive example always assumes the value is an object with the methods getId() and getUpdatedAt() method. The key then composed from the class name, the id and the updated time of the object:

Next the GenerationalCacheStrategy needs to be setup with the keygenerator.

Usage

The strategy expects an object as value for determining the cache key of the block:

Using multiple strategies

Different cache strategies are useful for different usecases. It is possible to mix multiple strategies in an application with the IndexedChainingCacheStrategy. The strategy takes an array of 'name' => $strategy and delegates the caching to the appropriate strategy.

Setup

Usage

The strategy expects an array with as key the name of the strategy which it needs to delegate to and as value the appropriate value for the delegated strategy.

Implementing a cache strategy

Creating separate caches for different access levels, languages or other usecases can be done by implementing a custom cache strategy. In order to do so implement the CacheProviderInterface. It is recommended to use composition and wrap a custom strategy around an existing one.

Authors

Alexander [email protected]

License

twig-cache-extension is licensed under the MIT License - see the LICENSE file for details


All versions of twig-cache-extension with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.2
twig/twig Version ^1.0|^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package asm89/twig-cache-extension contains the following files

Loading the files please wait ....