Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

cluster.php
Go to the documentation of this file.
1 <?php
11 abstract class ezpRestCacheStorageCluster extends ezpRestCacheStorageFile implements ezcCacheStackableStorage, ezcCacheStackMetaDataStorage
12 {
21 public $isCacheEnabled = true;
22
28 protected $clusterCacheFile;
29
38 public function __construct( $location, $options = array() )
39 {
40 $path = eZSys::cacheDirectory() . '/rest/' . $location;
41 if( !file_exists( $path ) )
42 {
43 if( !eZDir::mkdir( $path, false, true ) )
44 {
45 throw new ezcBaseFilePermissionException(
46 $path,
47 ezcBaseFileException::WRITE,
48 'Cache location is not writeable.'
49 );
50 }
51 }
52
53 parent::__construct( $path );
54 $this->properties['options'] = new ezpCacheStorageClusterOptions( $options );
55 }
56
61 public function store( $id, $data, $attributes = array() )
62 {
63 if ( !isset( $this->clusterCacheFile ) )
64 {
65 $this->clusterCacheFile = eZClusterFileHandler::instance(
66 $this->properties['location'] . $this->generateIdentifier( $id, $attributes )
67 );
68 }
69
70 $this->clusterCacheFile->storeCache(
71 array(
72 'scope' => 'rest-cluster-cache',
73 'binarydata' => $this->prepareData( $data )
74 )
75 );
76
77 return $id;
78 }
79
106 public function restore( $id, $attributes = array(), $search = false )
107 {
108 // If cache is explicitely disabled, we don't try to process it
109 if( $this->isCacheEnabled === false )
110 {
111 return false;
112 }
113
114 $this->clusterCacheFile = eZClusterFileHandler::instance(
115 $this->properties['location'] . $this->generateIdentifier( $id, $attributes )
116 );
117 $result = $this->clusterCacheFile->processCache(
118 array( $this, 'clusterRetrieve' ),
119 null, // We won't call any generate callback as we're using ezcCache mechanism, so it's up to the cache caller to generate
120 $this->properties['options']['ttl'],
121 null,
122 compact( 'id', 'attributes' )
123 );
124
125 if ( !$result instanceof eZClusterFileFailure )
126 {
127 return $result;
128 }
129
130 return false;
131 }
132
142 public function clusterRetrieve( $file, $mtime, $args )
143 {
144 return $this->fetchData( $file );
145 }
146
167 public function delete( $id = null, $attributes = array(), $search = false )
168 {
169 if ( !isset( $this->clusterCacheFile ) )
170 {
171 $this->clusterCacheFile = eZClusterFileHandler::instance(
172 $this->properties['location'] . $this->generateIdentifier( $id, $attributes )
173 );
174 }
175
176 $this->clusterCacheFile->purge();
177
178 return $id;
179 }
180
192 public function countDataItems( $id = null, $attributes = array() )
193 {
194 if ( !isset( $this->clusterCacheFile ) )
195 {
196 $this->clusterCacheFile = eZClusterFileHandler::instance(
197 $this->properties['location'] . $this->generateIdentifier( $id, $attributes )
198 );
199 }
200
201 return $this->clusterCacheFile->exists() ? 1 : 0;
202 }
203
215 public function getRemainingLifetime( $id, $attributes = array() )
216 {
217 if ( !isset( $this->clusterCacheFile ) )
218 {
219 $this->clusterCacheFile = eZClusterFileHandler::instance(
220 $this->properties['location'] . $this->generateIdentifier( $id, $attributes )
221 );
222 }
223
224 $ttl = $this->options->ttl;
225 $curTime = time();
226 if ( $ttl !== false && $this->clusterCacheFile->exists() && !$this->clusterCacheFile->isExpired( -1, $curTime, $ttl) )
227 {
228 $lifetime = $curTime - $this->clusterCacheFile->mtime();
229 if ( $lifetime < $ttl )
230 return $ttl - $lifetime;
231 }
232
233 return 0;
234 }
235
242 public function abortCacheGeneration()
243 {
244 if ( !isset( $this->clusterCacheFile ) )
245 {
246 throw new ezpCacheClusterException( "Can't abort generation of non-existent cluster cache" );
247 }
248
249 $this->clusterCacheFile->abortCacheGeneration();
250 }
251 }
252 ?>
eZClusterFileFailure
Definition: ezclusterfilefailure.php:21
eZClusterFileHandler\instance
static instance( $filename=false)
Definition: ezclusterfilehandler.php:22
eZDir\mkdir
static mkdir( $dir, $perm=false, $recursive=false)
Definition: ezdir.php:74
eZSys\cacheDirectory
static cacheDirectory()
Definition: ezsys.php:528
ezpCacheClusterException
Definition: exceptions/cluster.php:16
ezpCacheStorageClusterOptions
Definition: storage_cluster.php:16
ezpRestCacheStorageCluster
Definition: cluster.php:12
ezpRestCacheStorageCluster\store
store( $id, $data, $attributes=array())
Definition: cluster.php:61
ezpRestCacheStorageCluster\__construct
__construct( $location, $options=array())
Definition: cluster.php:38
ezpRestCacheStorageCluster\$isCacheEnabled
$isCacheEnabled
Definition: cluster.php:21
ezpRestCacheStorageCluster\clusterRetrieve
clusterRetrieve( $file, $mtime, $args)
Definition: cluster.php:142
ezpRestCacheStorageCluster\abortCacheGeneration
abortCacheGeneration()
Definition: cluster.php:242
ezpRestCacheStorageCluster\getRemainingLifetime
getRemainingLifetime( $id, $attributes=array())
Definition: cluster.php:215
ezpRestCacheStorageCluster\restore
restore( $id, $attributes=array(), $search=false)
Definition: cluster.php:106
ezpRestCacheStorageCluster\$clusterCacheFile
$clusterCacheFile
Definition: cluster.php:28
ezpRestCacheStorageCluster\countDataItems
countDataItems( $id=null, $attributes=array())
Definition: cluster.php:192
ezpRestCacheStorageFile
Definition: storage.php:12
$result
$result
Definition: companysearch.php:94
$args
$args
Definition: companytypelist.php:125
$id
$id
Definition: companytypelist.php:193
file_exists
static file_exists( $inifilename)
Definition: eZPBINIFile.php:195
$search
$search
Definition: export_froogle.php:153
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
properties
$def properties['rest_client_id']
Definition: ezprestauthorizedclient.php:21
$options
$options
Definition: optionlist.php:56
$location
$location
Definition: user/gotolink.php:43
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.