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

## Source for file memcache.php

Documentation is available at memcache.php

1. <?php
2. /**
3. * File containing the ezcCacheStorageMemcache 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 Memcache based storage classes.
30. * To implement a Memcache based cache storage, you simply have to derive
31. * from this class and implement the {@link ezcCacheStorageMemcache::fetchData()}
32. * and {@link ezcCacheStorageMemcache::prepareData()} methods.
33. *
34. * For example code of using a cache storage, see {@link ezcCacheManager}.
35. *
36. * The Cache package already contains an implementation this class:
37. * - {@link ezcCacheStorageMemcachePlain}
38. *
39. * Options for this class are defined in {@link ezcCacheStorageMemcacheOptions}.
40. *
41. * @package Cache
42. * @version //autogentag//
43. */
44. abstract class ezcCacheStorageMemcache extends ezcCacheStorageMemory
45. {
46. /**
47. * The backend name.
48. */
49. const BACKEND_NAME = "Memcache";
51. /**
52. * The registry name.
53. */
54. const REGISTRY_NAME = 'ezcCacheStorageMemcache_Registry';
56. /**
57. * Creates a new cache storage in the given location.
58. *
59. * Options can contain the 'ttl' ( Time-To-Life ). This is per default set
60. * to 1 day.
61. *
62. * For details about the options see {@link ezcCacheStorageMemcacheOptions}.
63. *
64. * @throws ezcBasePropertyNotFoundException
65. * If you tried to set a non-existent option value.
66. *
67. * @param string $location Path to the cache location
68. * @param array(string=>string) $options Options for the cache
69. */
70. public function __construct ( $location = null, array $options = array() )
71. {
72. parent:: __construct ( $location, array() );
74. // Overwrite parent set options with new ezcCacheMemcacheStorageOptions
75. $this-> properties ['options'] = new ezcCacheStorageMemcacheOptions ( $options );
77. $this-> backend = new ezcCacheMemcacheBackend ( array(
78. 'host' => $this-> properties ['options']->host,
79. 'port' => $this-> properties ['options']->port,
80. 'ttl' => $this-> properties ['options']->ttl,
81. 'persistent' => $this-> properties ['options']->persistent,
82. 'compressed' => $this-> properties ['options']->compressed,
83. ) );
85. $this-> registryName = self::REGISTRY_NAME;
86. $this-> backendName = self::BACKEND_NAME;
87. }
89. /**
90. * Fetches the data from the cache.
91. *
92. * @param string $identifier The memcache identifier to fetch data from
93. * @return mixed The fetched data or false on failure
94. */
95. abstract protected function fetchData ( $identifier );
97. /**
98. * Prepare the data for storing.
99. *
100. * @throws ezcCacheInvalidDataException
101. * If the data submitted can not be handled by this storage (object,
102. * resource).
103. *
104. * @param mixed $data Simple type or array
105. * @return mixed Prepared data
106. */
107. abstract protected function prepareData ( $data );
109. /**
110. * Property write access.
111. *
112. * @param string $propertyName Name of the property.
113. * @param mixed $val The value for the property.
114. *
115. * @throws ezcBaseValueException
116. * If the value for the property options is not an instance of
117. * ezcCacheStorageOptions.
118. * @ignore
119. */
120. public function __set( $propertyName, $val )
121. {
122. switch ( $propertyName )
123. {
124. case 'options':
125. $this-> setOptions ( $val );
126. return;
127. default:
128. parent::__set( $propertyName, $val );
129. }
130. }
132. /**
133. * Set new options.
134. *
135. * Overwrites the options with the given ones.
136. *
137. * @param ezcCacheStorageMemcacheOptions $options The options to set.
138. *
139. * @throws ezcBasePropertyNotFoundException
140. * If you tried to set a non-existent option value. The accepted
141. * options depend on the ezcCacheStorage implementation and may
142. * vary.
143. * @throws ezcBaseValueException
144. * If the value is not valid for the desired option.
145. * @throws ezcBaseValueException
146. * If you submit neither an array nor an instance of
147. * ezcCacheStorageOptions.
148. *
149. * @apichange Use $storage->options instead.
150. */
151. public function setOptions ( $options )
152. {
153. switch ( true )
154. {
155. case ( $options instanceof ezcCacheStorageMemcacheOptions ):
156. $this-> properties ['options'] = $options;
157. break;
158. case ( $options instanceof ezcCacheStorageOptions ):
159. $this-> properties ['options']->mergeStorageOptions( $options );
160. break;
161. case ( is_array ( $options ) ):
162. $this-> properties ['options']->merge( $options );
163. break;
164. default:
165. throw new ezcBaseValueException (
166. 'options',
167. $options,
168. 'instance of ezcCacheStorageMemcacheOptions'
169. );
170. }
171. }
172. }
173. ?>

Documentation generated by phpDocumentor 1.4.3