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

Class: Cache_Container_file

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

Class Overview


Stores cache contents in a file.



  • $Id: file.php 315100 2011-08-17 19:32:23Z cweiske $



Child classes:

Tri-file cache.

Inherited Variables

Inherited Methods

Class: Cache_Container

Decodes the data from the storage container.
Encodes the data for the storage container.
Fetches a dataset from the storage medium.
Flushes the cache - removes all caches datasets from the cache.
Flushes the internal preload buffer.
Starts the garbage collection.
Getter to allowed Configurations Options
Translates human readable/relative times in unixtime
Returns the userdata field of a cached data set.
Verify that a configuration option has been set
Checks if a dataset exists.
Checks if a dataset is cached.
Checks if a dataset is expired.
Loads a dataset from the cache.
Does a speculative preload of a dataset
Removes a dataset.
Stores a dataset.
Set the Allowed Parameters to Container Type
Imports the requested datafields as object variables if allowed

Class Details

[line 29]
Stores cache contents in a file.
  • Author: Ulf Wendel <>
  • Version: $Id: file.php 315100 2011-08-17 19:32:23Z cweiske $

[ Top ]

Class Variables

$cache_dir =  ''

[line 49]

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

Type:   string

[ Top ]

$entries =

[line 76]

List of cache entries, used within a gc run

Type:   array

[ Top ]

$fileLocking =  false

[line 42]

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 68]

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 96]

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 for details

Type:   int

[ Top ]

$total_size =  0

[line 83]

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

Type:   int

[ Top ]

Method Detail

Cache_Container_file (Constructor)   [line 103]

Cache_Container_file Cache_Container_file( [array $options = null])

Creates the cache directory if neccessary


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

[ Top ]

deleteDir   [line 380]

integer deleteDir( string $dir)

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


string   $dir   —  directory

[ Top ]

doGarbageCollection   [line 303]

void doGarbageCollection( integer $maxlifetime, string $dir)

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


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 128]

void fetch( $id, $group)

Overridden in child classes as:

Fetch cached file.

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


   $id   — 
   $group   — 

[ Top ]

flush   [line 236]

void flush( $group)

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


   $group   — 

[ Top ]

garbageCollection   [line 266]

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.)


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

[ Top ]

getFilename   [line 353]

string getFilename( string $id, string $group)

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


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

[ Top ]

idExists   [line 248]

void idExists( $id, $group)

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


   $id   — 
   $group   — 

[ Top ]

remove   [line 217]

void remove( $id, $group)

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


   $id   — 
   $group   — 

[ Top ]

save   [line 182]

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 file

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


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

[ Top ]

Documentation generated on Wed, 09 Dec 2015 22:56:40 +0000 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.