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

Class: Cache_Container

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

Class Overview


Common base class of all cache storage container.


Author(s):

Version:

  • $Id: Container.php 315102 2011-08-17 19:38:20Z cweiske $

Variables

Methods


Child classes:

Cache_Container_dbx
ext/dbx Cache Container.
Cache_Container_db
PEAR/DB Cache Container.
Cache_Container_file
Stores cache contents in a file.
Cache_Container_phplib
Stores cache data into a database table using PHPLibs DB abstraction.
Cache_Container_mdb
PEAR/MDB Cache Container.
Cache_Container_shm
Stores cache data into shared memory.
Cache_Container_msession
Stores cache contents in msessions.

Inherited Variables

Inherited Methods


Class Details

[line 47]
Common base class of all cache storage container.

To speed up things we do a preload you should know about, otherwise it might play you a trick. The Cache controller classes (Cache/Cache, Cache/Output, ...) usually do something like is (isCached($id) && !isExpired($id)) return $container->load($id). if you implement isCached(), isExpired() and load() straight ahead, each of this functions will result in a storage medium (db, file,...) access. This generates too much load. Now, a simple speculative preload should saves time in most cases. Whenever one of the mentioned methods is invoked we preload the cached dataset into class variables. That means that we have only one storage medium access for the sequence (isCached($id) && !isExpired($id)) return $container->load($id). The bad thing is that the preloaded data might be outdated meanwhile, which is unlikely but for you power users, be warned. If you do not want the preload you should switch it off by setting the class variable $preload to false. Anyway, this is not recommended!

  • Author: Ulf Wendel <ulf.wendel@phpdoc.de>
  • Version: $Id: Container.php 315102 2011-08-17 19:38:20Z cweiske $
  • Abstract:
  • Access: public


[ Top ]


Class Variables

$allowed_options = array('encoding_mode', 'highwater', 'lowwater')

[line 136]

Options that can be set in every derived class using it's constructor.

Type:   array


[ Top ]

$cachedata =  ''

[line 85]

Value of a preloaded dataset.

Type:   string


[ Top ]

$encoding_mode =  'base64'

[line 106]

Encoding mode for cache data: base64 or addslashes() (slash).
  • Var: base64 or slash

Type:   string


[ Top ]

$expires =  0

[line 78]

Expiration timestamp of a preloaded dataset.
  • Var: 0 means never, endless

Type:   integer


[ Top ]

$group =  ''

[line 71]

Cache group of a preloaded dataset

Type:   string


[ Top ]

$highwater =  2048000

[line 119]

Highwater mark - maximum space required by all cache entries.

Whenever the garbage collection runs it checks the amount of space required by all cache entries. If it's more than n (highwater) bytes the garbage collection deletes as many entries as necessary to reach the lowwater mark.


Type:   int


[ Top ]

$id =  ''

[line 64]

ID of a preloaded dataset

Type:   string


[ Top ]

$lowwater =  1536000

[line 128]

Lowwater mark

Type:   int


[ Top ]

$preload =  true

[line 57]

Flag indicating wheter to preload datasets.

See the class description for more details.


Type:   boolean


[ Top ]

$unknown =  true

[line 99]

Flag indicating that the dataset requested for preloading is unknown.

Type:   boolean


[ Top ]

$userdata =  ''

[line 92]

Preloaded userdata field.

Type:   string


[ Top ]



Method Detail

decode   [line 488]

void decode( $data)

Decodes the data from the storage container.

Parameters:

   $data   — 

[ Top ]

encode   [line 473]

void encode( $data)

Encodes the data for the storage container.
  • Var: data to encode

Parameters:

   $data   — 

[ Top ]

fetch   [line 267]

array fetch( string $id, string $group)

Fetches a dataset from the storage medium.
  • Return: format: [expire date, cached data, user data]
  • Abstract:
  • Throws: Cache_Error

Overridden in child classes as:

Cache_Container_dbx::fetch()
Cache_Container_db::fetch()
Cache_Container_file::fetch()
Cache_Container_trifile::fetch()
Fetch cached file.
Cache_Container_phplib::fetch()
Cache_Container_mdb::fetch()
Fetch in the db the data that matches input parameters
Cache_Container_shm::fetch()
Cache_Container_msession::fetch()

Parameters:

string   $id   —  dataset ID
string   $group   —  cache group

[ Top ]

flush   [line 316]

integer flush( string $group)

Flushes the cache - removes all caches datasets from the cache.
  • Return: Number of removed datasets, -1 on failure
  • Abstract:
  • Access: public

Overridden in child classes as:

Cache_Container_dbx::flush()
Cache_Container_db::flush()
Cache_Container_file::flush()
Cache_Container_phplib::flush()
Cache_Container_mdb::flush()
Remove all cached data for a certain group, or empty the cache table if no group is specified.
Cache_Container_shm::flush()
Cache_Container_msession::flush()

Parameters:

string   $group   —  If a cache group is given only the group will be flushed

[ Top ]

flushPreload   [line 393]

void flushPreload( [string $id = ''], [string $group = 'default'])

Flushes the internal preload buffer.

save(), remove() and flush() must call this method to preevent differences between the preloaded values and the real cache contents.


Parameters:

string   $id   —  dataset ID, if left out the preloaded values will be flushed. If given the preloaded values will only be flushed if they are equal to the given id and group
string   $group   —  cache group

[ Top ]

garbageCollection   [line 345]

void garbageCollection( int $gc_maxlifetime)

Starts the garbage collection.
  • Abstract:
  • Access: public

Overridden in child classes as:

Cache_Container_dbx::garbageCollection()
Cache_Container_db::garbageCollection()
Cache_Container_file::garbageCollection()
Deletes all expired files.
Cache_Container_phplib::garbageCollection()
Cache_Container_mdb::garbageCollection()
Garbage collector.
Cache_Container_shm::garbageCollection()
Cache_Container_msession::garbageCollection()
Deletes all expired files.

Parameters:

int   $gc_maxlifetime   —  The maximum lifetime (seconds) for a cache entry. Implemented by containers,

[ Top ]

getAllowedOptions   [line 463]

array getAllowedOptions( )

Getter to allowed Configurations Options
  • Return: The options you can set to Container
  • Access: protected

[ Top ]

getExpiresAbsolute   [line 509]

integer getExpiresAbsolute( mixed $expires)

Translates human readable/relative times in unixtime
  • Return: unix timestamp

Parameters:

mixed   $expires   —  can be in the following formats: human readable : yyyymmddhhmm[ss]] eg: 20010308095100 relative in seconds (1) : +xx eg: +10 relative in seconds (2) : x < 946681200 eg: 10 absolute unixtime : x < 2147483648 eg: 2147483648 see comments in code for details

[ Top ]

getUserdata   [line 173]

string getUserdata( string $id, string $group)

Returns the userdata field of a cached data set.
  • Return: userdata
  • Access: public

Parameters:

string   $id   —  dataset ID
string   $group   —  cache group

[ Top ]

hasBeenSet   [line 452]

boolean hasBeenSet( string $optionName)

Verify that a configuration option has been set
  • Access: protected

Parameters:

string   $optionName   —  the option name

[ Top ]

idExists   [line 331]

boolean idExists( string $id, string $group)

Checks if a dataset exists.
  • Abstract:
  • Access: public

Overridden in child classes as:

Cache_Container_dbx::idExists()
Cache_Container_db::idExists()
Cache_Container_file::idExists()
Cache_Container_phplib::idExists()
Cache_Container_mdb::idExists()
Check if a dataset ID/group exists.
Cache_Container_shm::idExists()
Cache_Container_msession::idExists()

Parameters:

string   $id   —  dataset ID
string   $group   —  cache group

[ Top ]

isCached   [line 243]

boolean isCached( string $id, string $group)

Checks if a dataset is cached.

Parameters:

string   $id   —  dataset ID
string   $group   —  cache group

[ Top ]

isExpired   [line 200]

boolean isExpired( string $id, string $group, integer $max_age)

Checks if a dataset is expired.
  • Access: public

Parameters:

string   $id   —  dataset ID
string   $group   —  cache group
integer   $max_age   —  maximum age timestamp

[ Top ]

load   [line 147]

mixed load( string $id, string $group)

Loads a dataset from the cache.
  • Return: dataset value or null on failure
  • Access: public

Parameters:

string   $id   —  dataset ID
string   $group   —  cache group

[ Top ]

preload   [line 357]

boolean preload( string $id, string $group)

Does a speculative preload of a dataset

Parameters:

string   $id   —  dataset ID
string   $group   —  cache group

[ Top ]

remove   [line 302]

boolean remove( string $id, string $group)

Removes a dataset.
  • Abstract:
  • Access: public

Overridden in child classes as:

Cache_Container_dbx::remove()
Cache_Container_db::remove()
Cache_Container_file::remove()
Cache_Container_phplib::remove()
Cache_Container_mdb::remove()
Removes a dataset from the database
Cache_Container_shm::remove()
Cache_Container_msession::remove()

Parameters:

string   $id   —  dataset ID
string   $group   —  cache group

[ Top ]

save   [line 285]

boolean save( string $id, mixed $data, mixed $expire, string $group, string $userdata)

Stores a dataset.
  • Abstract:
  • Throws: Cache_Error
  • Access: public

Overridden in child classes as:

Cache_Container_dbx::save()
Stores a dataset.
Cache_Container_db::save()
Stores a dataset.
Cache_Container_file::save()
Stores a dataset.
Cache_Container_trifile::save()
Cache file
Cache_Container_phplib::save()
Stores a dataset.
Cache_Container_mdb::save()
Stores a dataset in the database
Cache_Container_shm::save()
Cache_Container_msession::save()
Stores a dataset.

Parameters:

string   $id   —  dataset ID
mixed   $data   —  data to store
mixed   $expire   —  userdefined expire date
string   $group   —  cache group
string   $userdata   —  additional userdefined data

[ Top ]

setAllowedOptions   [line 435]

boolean setAllowedOptions( array $allowedOptions)

Set the Allowed Parameters to Container Type
  • Access: protected

Parameters:

array   $allowedOptions   —  the Array with allowed parameters

[ Top ]

setOptions   [line 414]

boolean setOptions( array $requested)

Imports the requested datafields as object variables if allowed
  • Return: True if all parametes in arg are accepted
  • Access: protected

Parameters:

array   $requested   —  list of fields to be imported

[ Top ]


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