## Apache Zeta Components Manual :: File Source for apc.php

## Source for file apc.php

Documentation is available at apc.php

1. <?php
2. /**
3. * File containing the ezcCacheStorageApc class.
4. *
5. * Licensed to the Apache Software Foundation (ASF) under one
6. * or more contributor license agreements. See the NOTICE file
7. * distributed with this work for additional information
8. * regarding copyright ownership. The ASF licenses this file
9. * to you under the Apache License, Version 2.0 (the
10. * "License"); you may not use this file except in compliance
11. * with the License. You may obtain a copy of the License at
12. *
13. * http://www.apache.org/licenses/LICENSE-2.0
14. *
15. * Unless required by applicable law or agreed to in writing,
16. * software distributed under the License is distributed on an
17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18. * KIND, either express or implied. See the License for the
19. * specific language governing permissions and limitations
20. * under the License.
21. *
22. * @package Cache
23. * @version //autogentag//
24. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
25. * @filesource
26. */
28. /**
29. * This class is a common base class for all APC based storage classes.
30. * To implement an APC based cache storage, you simply have to derive
31. * from this class and implement the {@link ezcCacheStorageApc::fetchData()}
32. * and {@link ezcCacheStorageApc::prepareData()} methods.
33. *
34. * For example code of using a cache storage, see {@link ezcCacheManager}.
35. *
36. * The Cache package already contains these implementations of this class:
37. * - {@link ezcCacheStorageApcPlain}
38. * - {@link ezcCacheStorageFileApcArray}
39. *
40. * This storage acan also be used with {@link ezcCacheStack}. However, APC
41. * version 3.0.16 or newer is required for that.
42. *
43. * @package Cache
44. * @version //autogentag//
45. */
46. abstract class ezcCacheStorageApc extends ezcCacheStorageMemory
47. {
48. /**
49. * The backend name.
50. */
51. const BACKEND_NAME = "Apc";
53. /**
54. * The registry name.
55. */
56. const REGISTRY_NAME = 'ezcCacheStorageApc_Registry';
58. /**
59. * Creates a new cache storage in the given location.
60. *
61. * Options can contain the 'ttl' (Time-To-Live). This is per default set
62. * to 1 day.
63. *
64. * For details about the options see {@link ezcCacheStorageApcOptions}.
65. *
66. * @throws ezcBasePropertyNotFoundException
67. * If you tried to set a non-existent option value.
68. *
69. * @param string $location Path to the cache location
70. * @param array(string=>string) $options Options for the cache
71. */
72. public function __construct ( $location = null, array $options = array() )
73. {
74. parent:: __construct ( $location, array() );
76. // Overwrite parent set options with new ezcCacheStorageApcOptions
77. $this-> properties ['options'] = new ezcCacheStorageApcOptions ( $options );
79. $this-> backend = new ezcCacheApcBackend ();
80. $this-> registryName = self::REGISTRY_NAME;
81. $this-> backendName = self::BACKEND_NAME;
82. }
84. /**
85. * Fetches data from the cache.
86. *
87. * @param string $identifier The APC identifier to fetch data from
88. * @return mixed The fetched data or false on failure
89. */
90. abstract protected function fetchData ( $identifier );
92. /**
93. * Prepares the data for storing.
94. *
95. * @throws ezcCacheInvalidDataException
96. * If the data submitted can not be handled by this storage (object,
97. * resource).
98. *
99. * @param mixed $data Simple type or array
100. * @return mixed Prepared data
101. */
102. abstract protected function prepareData ( $data );
104. /**
105. * Property write access.
106. *
107. * @param string $propertyName Name of the property.
108. * @param mixed $val The value for the property.
109. *
110. * @throws ezcBaseValueException
111. * If the value for the property options is not an instance of
112. * ezcCacheStorageOptions.
113. * @ignore
114. */
115. public function __set( $propertyName, $val )
116. {
117. switch ( $propertyName )
118. {
119. case 'options':
120. $this-> setOptions ( $val );
121. return;
122. default:
123. parent::__set( $propertyName, $val );
124. }
125. }
127. /**
128. * Return the currently set options.
129. *
130. * Return the currently set options. The options are returned on an array
131. * that has the same format as the one passed to
132. * {@link ezcCacheStorage::setOptions()}. The possible options for a storage
133. * depend on its implementation.
134. *
135. * @param ezcCacheStorageOptions $options
136. *
137. * @apichange Use $storage->options instead.
138. */
139. public function setOptions ( $options )
140. {
141. switch ( true )
142. {
143. case ( $options instanceof ezcCacheStorageApcOptions ):
144. $this-> properties ['options'] = $options;
145. break;
146. case ( $options instanceof ezcCacheStorageOptions ):
147. $this-> properties ['options']->mergeStorageOptions( $options );
148. break;
149. case ( is_array ( $options ) ):
150. $this-> properties ['options']->merge( $options );
151. break;
152. default:
153. throw new ezcBaseValueException (
154. 'options',
155. $options,
156. 'instance of ezcCacheStorageApcOptions'
157. );
158. }
159. }
160. }
161. ?>

Documentation generated by phpDocumentor 1.4.3