Source for file CacheSet.php
Documentation is available at CacheSet.php
* Data Structures for PHP similar to Java's HashSet and LinkedHashSet. Uses
* memcached as a storage mechanism for persisting set data beyond the scope of
* Requires: {@link http://www.php.net/ PHP 5},
* {@link http://www.danga.com/memcached/ memcached} and
* {@link http://pecl.php.net/memcache pecl_memcache}
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* @category HighPerformance
* @copyright Coypright (c) 2008 Jeff Trudeau
* @license http://www.opensource.org/licenses/mit-license.php MIT License
require_once(dirname(__FILE__
) .
'/CacheFactory.php');
require_once(dirname(__FILE__
) .
'/properties.php');
* Quasi-equivalent (superior in some repects) to Java's HashSet. Uses
* memcached as a storage mechanism for persisting set data beyond the scope of
* Adds the specified element to the end of the set.
public function add($value) {
* Returns true if the specified element is contained within the set, or
* Creates a copy (clone) of the internal set. As changes to the copy are
* not persisted in the cache, this is used mainly for performing read/sort
* operations externally on the set.
public function ©() {
* Deletes and returns the specified element from the set, or returns null
* if the element does not exist.
public function delete($key) {
* Returns the specified element from the set, or null if the element does
public function get($key) {
* Returns the index of the element referenced by the specified key from
* the set, or -1 if the key does not exist.
for ($i =
0; $i <
$this->size(); $i++
) {
* Returns whether or not the set is empty.
return empty($this->set) ||
$this->size() ==
0;
* Retrieves the internal set from the cache.
protected function load() {
* Deletes the internal set from the cache.
public function purge() {
* Persists the internal set to the cache.
protected function save() {
* Updates the specified element's value within the set.
public function set($key, $value) {
$this->set[$key] =
$value;
* Returns the number of elements in the set.
* CacheSet's internal sorting facility, which uses PHP's array value
* sorting functions. The default assumes a non-associative set, and sorts
* in ascending order of values.
* @param boolean $keepAssoc = false
* @param boolean $reverseOrder = false
public function sort($keepAssoc =
false, $reverseOrder =
false) {
if ($keepAssoc &&
$reverseOrder) {
else if ($reverseOrder) {
* CacheSet's internal sorting facility, which uses PHP's array key sorting
* functions. The default sorts in ascending order of keys.
* @param boolean $reverseOrder = false
public function sortByKey($reverseOrder =
false) {
$func =
$reverseOrder ?
'krsort' :
'ksort';
* Updates the internal set. Useful in conjunction with copy() if advanced
* sorting operations are required on the set - simply use copy() to create
* a local clone of the set, perform the necessary operations on the clone,
* then use update() to refresh the structure and contents of the set.
public function update(&$set) {
* Returns the value of the element referenced by the specified key from
* the set, or null if the key does not exist.
return $this->set[$keys[$index]];
Documentation generated on Thu, 14 Feb 2008 09:14:27 -0500 by phpDocumentor 1.4.1