mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 11:27:00 +00:00
rewrote the recipes about APC and opcache to avoid deprecation notices
This commit is contained in:
+37
-10
@@ -337,25 +337,52 @@ Refreshing modified Templates when OPcache or APC is enabled
|
||||
|
||||
When using OPcache with ``opcache.validate_timestamps`` set to ``0`` or APC
|
||||
with ``apc.stat`` set to ``0`` and Twig cache enabled, clearing the template
|
||||
cache won't update the cache. To get around this, one can extend
|
||||
``Twig_Environment`` and force the update of the cache when Twig rewrites the
|
||||
cache::
|
||||
cache won't update the cache.
|
||||
|
||||
class Twig_Environment_APC extends Twig_Environment
|
||||
To get around this, create a custom ``Twig_Cache_Interface`` implementation and
|
||||
force the update of the cache when Twig rewrites the cache::
|
||||
|
||||
class OpCacheAwareCacheFilesystem extends Twig_Cache_Filesystem
|
||||
{
|
||||
protected function writeCacheFile($file, $content)
|
||||
public function write($key, $content)
|
||||
{
|
||||
parent::writeCacheFile($file, $content);
|
||||
parent::write($key, $content);
|
||||
|
||||
// Compile cached file into bytecode cache
|
||||
if (extension_loaded('Zend OPcache') && ini_get('opcache.enable')) {
|
||||
opcache_invalidate($file);
|
||||
} elseif (extension_loaded('apc') && ini_get('apc.enabled')) {
|
||||
apc_compile_file($file);
|
||||
if (function_exists('opcache_invalidate') && ini_get('opcache.enable')) {
|
||||
opcache_invalidate($key);
|
||||
} elseif (function_exists('apc_compile_file') && ini_get('apc.enabled')) {
|
||||
apc_compile_file($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Then, use that new class as the template cache::
|
||||
|
||||
$twig = new Twig_Environment($loader, array(
|
||||
'cache' => new OpCacheAwareCacheFilesystem('/some/cache/path'),
|
||||
// ...
|
||||
));
|
||||
|
||||
.. note::
|
||||
|
||||
Before Twig 1.22, you should extend ``Twig_Environment`` instead::
|
||||
|
||||
class OpCacheAwareTwigEnvironment extends Twig_Environment
|
||||
{
|
||||
protected function writeCacheFile($file, $content)
|
||||
{
|
||||
parent::writeCacheFile($file, $content);
|
||||
|
||||
// Compile cached file into bytecode cache
|
||||
if (function_exists('opcache_invalidate') && ini_get('opcache.enable')) {
|
||||
opcache_invalidate($file);
|
||||
} elseif (function_exists('apc_compile_file') && ini_get('apc.enabled')) {
|
||||
apc_compile_file($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reusing a stateful Node Visitor
|
||||
-------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user