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

Class: Cache_Container_file

Source Location: /Cache-1.5.4/Container/file.php

Class Overview

Cache_Container
   |
   --Cache_Container_file

Stores cache contents in a file.


Author(s):

Version:

  • $Id: file.php,v 1.13 2003/03/27 10:48:42 chregu Exp $

Variables

Methods


Child classes:

Cache_Container_trifile
Tri-file cache.

Inherited Variables

Inherited Methods

Class: Cache_Container

Cache_Container::decode()
Decodes the data from the storage container.
Cache_Container::encode()
Encodes the data for the storage container.
Cache_Container::fetch()
Fetches a dataset from the storage medium.
Cache_Container::flush()
Flushes the cache - removes all caches datasets from the cache.
Cache_Container::flushPreload()
Flushes the internal preload buffer.
Cache_Container::garbageCollection()
Starts the garbage collection.
Cache_Container::getExpiresAbsolute()
Translates human readable/relative times in unixtime
Cache_Container::getUserdata()
Returns the userdata field of a cached data set.
Cache_Container::idExists()
Checks if a dataset exists.
Cache_Container::isCached()
Checks if a dataset is cached.
Cache_Container::isExpired()
Checks if a dataset is expired.
Cache_Container::load()
Loads a dataset from the cache.
Cache_Container::preload()
Does a speculative preload of a dataset
Cache_Container::remove()
Removes a dataset.
Cache_Container::save()
Stores a dataset.
Cache_Container::setOptions()
Imports the requested datafields as object variables if allowed

Class Details

[line 29]
Stores cache contents in a file.
  • Author: Ulf Wendel <ulf.wendel@phpdoc.de>
  • Version: $Id: file.php,v 1.13 2003/03/27 10:48:42 chregu Exp $


[ Top ]


Class Variables

$cache_dir =  ''

[line 48]

Directory where to put the cache files.
  • Var: Make sure to add a trailing slash

Type:   string


[ Top ]

$entries =

[line 75]

List of cache entries, used within a gc run

Type:   array


[ Top ]

$fileLocking =  false

[line 41]

File locking

With file container, it's possible, that you get corrupted data-entries under bad circumstances. The file locking must improve this problem but it's experimental stuff. So the default value is false. But it seems to give good results


Type:   boolean


[ Top ]

$filename_prefix =  ''

[line 67]

Filename prefix for cache files.

You can use the filename prefix to implement a "domain" based cache or just to give the files a more descriptive name. The word "domain" is borroed from a user authentification system. One user id (cached dataset with the ID x) may exists in different domains (different filename prefix). You might want to use this to have different cache values for a production, development and quality assurance system. If you want the production cache not to be influenced by the quality assurance activities, use different filename prefixes for them.

I personally don't think that you'll never need this, but 640kb happend to be not enough, so... you know what I mean. If you find a useful application of the feature please update this inline doc.


Type:   string


[ Top ]

$max_userdata_linelength =  257

[line 95]

Max Line Length of userdata

If set to 0, it will take the default ( 1024 in php 4.2, unlimited in php 4.3) see http://ch.php.net/manual/en/function.fgets.php for details


Type:   int


[ Top ]

$total_size =  0

[line 82]

Total number of bytes required by all cache entries, used within a gc run.

Type:   int


[ Top ]



Method Detail

Cache_Container_file (Constructor)   [line 102]

Cache_Container_file Cache_Container_file( [array $options = ''])

Creates the cache directory if neccessary

Parameters:

array   $options   —  Config options: ["cache_dir" => ..., "filename_prefix" => ...]

[ Top ]

deleteDir   [line 355]

integer deleteDir( string $dir)

Deletes a directory and all files in it.
  • Return: number of removed files
  • Throws: Cache_Error

Parameters:

string   $dir   —  directory

[ Top ]

doGarbageCollection   [line 284]

void doGarbageCollection( integer $maxlifetime, string $dir)

Does the recursive gc procedure, protected.
  • Throws: Cache_Error

Parameters:

integer   $maxlifetime   —  Maximum lifetime in seconds of an no longer used/touched entry
string   $dir   —  directory to examine - don't sets this parameter, it's used for a recursive function call!

[ Top ]

fetch   [line 126]

void fetch( $id, $group)


Overridden in child classes as:

Cache_Container_trifile::fetch()
Fetch cached file.

Overrides Cache_Container::fetch() (Fetches a dataset from the storage medium.)

Parameters:

   $id   — 
   $group   — 

[ Top ]

flush   [line 219]

void flush( $group)


Overrides Cache_Container::flush() (Flushes the cache - removes all caches datasets from the cache.)

Parameters:

   $group   — 

[ Top ]

garbageCollection   [line 248]

void garbageCollection( integer $maxlifetime)

Deletes all expired files.

Garbage collection for files is a rather "expensive", "long time" operation. All files in the cache directory have to be examined which means that they must be opened for reading, the expiration date has to be read from them and if neccessary they have to be unlinked (removed). If you have a user comment for a good default gc probability please add it to to the inline docs.

  • Throws: Cache_Error

Overrides Cache_Container::garbageCollection() (Starts the garbage collection.)

Parameters:

integer   $maxlifetime   —  Maximum lifetime in seconds of an no longer used/touched entry

[ Top ]

getFilename   [line 332]

string getFilename( string $id, string $group)

Returns the filename for the specified id.
  • Return: full filename with the path
  • Access: public

Parameters:

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

[ Top ]

idExists   [line 230]

void idExists( $id, $group)


Overrides Cache_Container::idExists() (Checks if a dataset exists.)

Parameters:

   $id   — 
   $group   — 

[ Top ]

remove   [line 204]

void remove( $id, $group)


Overrides Cache_Container::remove() (Removes a dataset.)

Parameters:

   $id   — 
   $group   — 

[ Top ]

save   [line 171]

void save( $id, $cachedata, $expires, $group, $userdata)

Stores a dataset.

WARNING: If you supply userdata it must not contain any linebreaks, otherwise it will break the filestructure.


Overridden in child classes as:

Cache_Container_trifile::save()
Cache file

Overrides Cache_Container::save() (Stores a dataset.)

Parameters:

   $id   — 
   $cachedata   — 
   $expires   — 
   $group   — 
   $userdata   — 

[ Top ]


Documentation generated on Mon, 11 Mar 2019 10:14:24 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.