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

Class: Cache_Container_file

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

Class Overview

Cache_Container
   |
   --Cache_Container_file

Stores cache contents in a file.


Author(s):

Version:

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

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::getAllowedOptions()
Getter to allowed Configurations Options
Cache_Container::getExpiresAbsolute()
Translates human readable/relative times in unixtime
Cache_Container::getUserdata()
Returns the userdata field of a cached data set.
Cache_Container::hasBeenSet()
Verify that a configuration option has been 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::setAllowedOptions()
Set the Allowed Parameters to Container Type
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 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 http://ch.php.net/manual/en/function.fgets.php 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

Parameters:

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

Parameters:

string   $dir   —  directory

[ Top ]

doGarbageCollection   [line 303]

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

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

void flush( $group)


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

Parameters:

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

Parameters:

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

Parameters:

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

Parameters:

   $id   — 
   $group   — 

[ Top ]

remove   [line 217]

void remove( $id, $group)


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

Parameters:

   $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_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 15:44:49 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.