Cache
[ class tree: Cache ] [ index: Cache ] [ all elements ]

Class: Cache_Application

Source Location: /Cache-1.5.7/Cache/Application.php

Class Overview

PEAR
   |
   --Cache
      |
      --Cache_Application

Cache is a base class for cache implementations.


Author(s):

Version:

  • $Id: Cache.php 316194 2011-09-05 20:35:25Z cweiske $

Variables

Methods


Inherited Variables

Inherited Methods

Class: Cache

Cache::Cache()
this Constructor set the Container Property as a Cache_Container|Cache_Error Object.
Cache::extSave()
Stores a dataset with additional userdefined data.
Cache::flush()
Flushes the cache - removes all data from it
Cache::garbageCollection()
Calls the garbage collector of the storage object with a certain probability
Cache::generateID()
Generates a "unique" ID for the given value
Cache::get()
Returns the requested dataset it if exists and is not expired
Cache::getCaching()
Returns the current caching state.
Cache::getUserdata()
Returns the userdata field of a cached data set.
Cache::isCached()
Checks if a dataset exists.
Cache::isExpired()
Checks if a dataset is expired
Cache::load()
Loads the given ID from the cache.
Cache::remove()
Removes the specified dataset from the cache.
Cache::save()
Stores the given data in the cache.
Cache::setCaching()
Enables or disables caching.
Cache::_Cache()

Class Details

[line 73]
Cache is a base class for cache implementations.

The pear cache module is a generic data cache which can be used to cache script runs. The idea behind the cache is quite simple. If you have the same input parameters for whatever tasks/algorithm you use you'll usually get the same output. So why not caching templates, functions calls, graphic generation etc. Caching certain actions e.g. XSLT tranformations saves you lots of time.

The design of the cache reminds of PHPLibs session implementation. A (PHPLib: session) controller uses storage container (PHPLib: ct_*.inc) to save certain data (PHPLib: session data). In contrast to the session stuff it's up to you to generate an ID for the data to cache. If you're using the output cache you might use the script name as a seed for cache::generateID(), if your using the function cache you'd use an array with all function parameters.

Usage example of the generic data cache:

require_once('Cache.php');

$cache = new Cache('file', array('cache_dir' => 'cache/') ); $id = $cache->generateID('testentry');

if ($data = $cache->get($id)) { print "Cache hit.
Data: $data";

} else { $data = 'data of any kind'; $cache->save($id, $data); print 'Cache miss.
'; }

WARNING: No File/DB-Table-Row locking is implemented yet, it's possible, that you get corrupted data-entries under bad circumstances (especially with the file container)

  • Author: Ulf Wendel <ulf.wendel@phpdoc.de>
  • Version: $Id: Cache.php 316194 2011-09-05 20:35:25Z cweiske $


[ Top ]


Class Variables

$data =

[line 76]


Type:   mixed


[ Top ]

$group =

[line 78]


Type:   mixed


[ Top ]

$id =

[line 77]


Type:   mixed


[ Top ]

$registered_vars =

[line 79]


Type:   mixed


[ Top ]



Method Detail

Cache_Application (Constructor)   [line 87]

Cache_Application Cache_Application( [string $container = 'file'], [array $container_options = array('cache_dir' => '/tmp/', 'filename_prefix' => 'cache_')], [ $id = 'application_var'], [ $group = 'application_cache'])

Constructor

Parameters:

string   $container   —  Name of container class
array   $container_options   —  Array with container class options
   $id   — 
   $group   — 

[ Top ]

_Cache_Application (Destructor)   [line 111]

void _Cache_Application( )

Destructor

Gets values of all registered variables and stores them. Then calls save() to write data away.


[ Top ]

clear   [line 161]

void clear( )

clear()

Removes all stored data


[ Top ]

getData   [line 174]

mixed &getData( )

getData()

Use this to get a reference to the data to manipulate in calling script. Eg. $_APP =& $obj->getData();

  • Return: A reference to the data

[ Top ]

register   [line 133]

void register( string $varname, [mixed $data = null])

register()

Registers a variable to be stored.


Parameters:

string   $varname   —  Name of variable to register
mixed   $data   —  Optional data to store

[ Top ]

unregister   [line 149]

void unregister( string $varname)

unregister()

Unregisters a variable from being stored.


Parameters:

string   $varname   —  Name of variable to unregister

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:44:49 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.