Apache Zeta Components Manual :: File Source for cache_backend.php
Source for file cache_backend.php
Documentation is available at cache_backend.php
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @version //autogentag//
* @package TranslationCacheTiein
* Translation backend that reads translation data from a cache.
* This class is a backend implementation for the Translation system. This
* specific one uses the Cache Component to store and serve cached translation
* Example that uses both the {@link ezcCacheStorageFileArray} and {@link }
* ezcTranslationCacheBackend} classes:
* // Create a cache object with content
* $cacheObj = new ezcCacheStorageFileArray( 'ezcTranslationCacheBackendTest' );
* new ezcTranslationData( 'Node ID: %node_id Visibility: %visibility',
* 'Knoop ID: %node_id Zichtbaar: %visibility',
* false, ezcTranslationData::TRANSLATED )
* $cacheObj->store( 'nl-nl/contentstructuremenu/show_content_structure', $expected );
* // Use the cache backend
* $backend = new ezcTranslationCacheBackend( $cacheObj );
* $context = $backend->getContext( 'nl-nl', 'contentstructuremenu/show_content_structure' );
* $translation = new ezcTranslation( $context );
* echo $translation->getTranslation( 'Node ID: %node_id Visibility: %visibility',
* array( 'node_id' => 42, 'visibility' => 'yes' ) );
* Example that stores a whole translation file into a cache by using {@link }
* ezcTranslationContextRead} interface that is implemented by the {@link }
* ezcTranslationTsBackend} and the {@link ezcTranslationContextWrite}
* interface that is implemented by this class:
* // Setup the cache object
* $cacheObj = new ezcCacheStorageFileArray( 'ezcTranslationCacheBackendTest' );
* // Initialize the writer
* $writer = new ezcTranslationCacheBackend( $cacheObj );
* $writer->initWriter( $locale );
* // Initialize the reader
* $reader = new ezcTranslationTsBackend( "translations" );
* $reader->setOptions( array ( 'format' => '[LOCALE].xml' ) );
* $reader->initReader( $locale );
* foreach ( $reader as $contextName => $contextData )
* $writer->storeContext( $contextName, $contextData );
* // Deinitialize the writer and reader
* $writer->deinitWriter();
* $reader->deinitReader();
* @package TranslationCacheTiein
* @version //autogentag//
* Stores the cache object to use for storing and fetching.
* @var ezcCacheStorageFileArray
* The locale to write to.
* Constructs a new ezcTranslationCacheBackend that will store data to $cacheObject.
* @param ezcCacheStorageFileArray $cacheObject
public function __construct( ezcCacheStorageFileArray $cacheObject )
$this->cache =
$cacheObject;
* Sets configuration data
* This backend accepts no settings at all, and will always throw an
* ezcBaseSettingNotFoundException for every setting that is contained
* in the $configurationData.
* @param array $configurationData
* @throws ezcBaseSettingNotFoundException if an unknown setting is passed.
* @todo Implement ezcBaseOptions class, if options are added.
foreach ( $configurationData as $name =>
$value )
* Returns a array containing the translation map for the specified
* It uses the $tsLocationPath and
* $tsFilenameFormat properties to locate the file, unless caching is
* enabled. If a cache object is available it will be used to retrieve the
* information from the cache.
* @throws ezcTranslationContextNotAvailableException if the context is not available.
* @return array(ezcTranslationData)
$cachedContext =
$this->cache->restore( "$locale/$context" );
if ( $cachedContext ===
false )
foreach ( $cachedContext as $key =>
$cachedElement )
unset
( $cachedContext[$key] );
* Initializes the writer to write to the locale $locale.
* Before starting to writer contexts to the writer, you should call
* this method to initialize it.
$this->writeLocale =
$locale;
* Deinitializes the writer.
* This method should be called after the last context was written to
* @throws ezcTranslationWriterNotInitializedException when the writer is
* not initialized with initWriter().
if ( is_null( $this->writeLocale ) )
$this->writeLocale =
null;
* This method stores the context that it received to the backend specified
* @throws ezcTranslationWriterNotInitializedException when the writer is
* not initialized with initWriter().
* @param string $context The context's name
* @param array(ezcTranslationData) $data The context's translation map
if ( is_null( $this->writeLocale ) )
foreach ( $data as $key =>
$cachedElement )
if ( $cachedElement->status ==
ezcTranslationData::OBSOLETE )
$cachedContext =
$this->cache->store( "{
$this->writeLocale}/
$context" , $data );