Overview

Packages

  • Framework
  • None
  • PHP
  • Utilitaire

Classes

  • CacheFichier
  • CacheSqlite
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class CacheFichier

Located at CacheFichier.php
Methods summary
public
# __construct( array $options = array(), Cache $cache )

Constructor

Constructor

Parameters

$options
array
$options associative array of options
$cache

Throws

Zend_Cache_Exception
public
# setEmplacement( mixed $emplacement )
public string|false
# charger( string $id, boolean $ne_pas_tester_validiter_du_cache = false )

Test if a cache is available for the given id and (if yes) return it (false else)

Test if a cache is available for the given id and (if yes) return it (false else)

Parameters

$id
string
$id cache id
$ne_pas_tester_validiter_du_cache
boolean
$doNotTestCacheValidity if set to true, the cache validity won't be tested

Returns

string|false
cached datas
public mixed
# tester( string $id )

Teste si un enregistrement en cache est disponible ou pas (pour l'id passé en paramètre).

Teste si un enregistrement en cache est disponible ou pas (pour l'id passé en paramètre).

Parameters

$id
string
$id identifiant de cache.

Returns

mixed
false (le cache n'est pas disponible) ou timestamp (int) "de dernière modification" de l'enregistrement en cache
public boolean
# sauver( string $donnees, string $id, array $tags = array(), integer $duree_vie_specifique = false )

Save some string datas into a cache record

Save some string datas into a cache record

Note : $data is always "string" (serialization is done by the core not by the backend)

Parameters

$donnees
string
$data Datas to cache
$id
string
$id Cache id
$tags
array
$tags Array of strings, the cache record will be tagged by each string entry
$duree_vie_specifique
integer
$specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)

Returns

boolean
true if no problem
public boolean
# supprimer( string $id )

Remove a cache record

Remove a cache record

Parameters

$id
string
$id cache id

Returns

boolean
true if no problem
public boolean
# nettoyer( string $mode = Cache::NETTOYAGE_MODE_TOUS, tags $tags = array() )

Clean some cache records

Clean some cache records

Available modes are : 'all' (default) => remove all cache entries ($tags is not used) 'old' => remove too old cache entries ($tags is not used) 'matchingTag' => remove cache entries matching all given tags ($tags can be an array of strings or a single string) 'notMatchingTag' => remove cache entries not matching one of the given tags ($tags can be an array of strings or a single string) 'matchingAnyTag' => remove cache entries matching any given tags ($tags can be an array of strings or a single string)

Parameters

$mode
string
$mode clean mode
$tags
tags
array $tags array of tags

Returns

boolean
true if no problem
public array
# getIds( )

Return an array of stored cache ids

Return an array of stored cache ids

Returns

array
array of stored cache ids (string)
public array
# getTags( )

Return an array of stored tags

Return an array of stored tags

Returns

array
array of stored tags (string)
public array
# getIdsAvecLesTags( array $tags = array() )

Return an array of stored cache ids which match given tags

Return an array of stored cache ids which match given tags

In case of multiple tags, a logical AND is made between tags

Parameters

$tags
array
$tags array of tags

Returns

array
array of matching cache ids (string)
public array
# getIdsSansLesTags( array $tags = array() )

Return an array of stored cache ids which don't match given tags

Return an array of stored cache ids which don't match given tags

In case of multiple tags, a logical OR is made between tags

Parameters

$tags
array
$tags array of tags

Returns

array
array of not matching cache ids (string)
public array
# getIdsAvecUnTag( array $tags = array() )

Return an array of stored cache ids which match any given tags

Return an array of stored cache ids which match any given tags

In case of multiple tags, a logical AND is made between tags

Parameters

$tags
array
$tags array of tags

Returns

array
array of any matching cache ids (string)
public integer
# getPourcentageRemplissage( )

Return the filling percentage of the backend storage

Return the filling percentage of the backend storage

Returns

integer
integer between 0 and 100

Throws

Zend_Cache_Exception
public array
# getMetadonnees( string $id )

Return an array of metadatas for the given cache id

Return an array of metadatas for the given cache id

The array must include these keys :

  • expire : the expire timestamp
  • tags : a string array of tags
  • mtime : timestamp of last modification time

Parameters

$id
string
$id cache id

Returns

array
array of metadatas (false if the cache id is not found)
public boolean
# ajouterSupplementDureeDeVie( string $id, integer $supplement_duree_de_vie )

Give (if possible) an extra lifetime to the given cache id

Give (if possible) an extra lifetime to the given cache id

Parameters

$id
string
$id cache id
$supplement_duree_de_vie
integer
$extraLifetime

Returns

boolean
true if ok
protected array|false
# getMetadonneesFichier( string $id )

Get a metadatas record

Get a metadatas record

Parameters

$id
string
$id Cache id

Returns

array|false
Associative array of metadatas
protected boolean
# setMetadonnees( string $id, array $metadonnees, boolean $sauvegarde = true )

Set a metadatas record

Set a metadatas record

Parameters

$id
string
$id Cache id
$metadonnees
array
$metadatas Associative array of metadatas
$sauvegarde
boolean
$save optional pass false to disable saving to file

Returns

boolean
True if no problem
protected boolean
# supprimerMetadonnees( string $id )

Drop a metadata record

Drop a metadata record

Parameters

$id
string
$id Cache id

Returns

boolean
True if no problem
protected
# nettoyerMetadonnees( )

Clear the metadatas array

Clear the metadatas array

protected array|false
# chargerMetadonnees( string $id )

Load metadatas from disk

Load metadatas from disk

Parameters

$id
string
$id Cache id

Returns

array|false
Metadatas associative array
protected boolean
# sauverMetadonnees( string $id, array $metadonnees )

Save metadatas to disk

Save metadatas to disk

Parameters

$id
string
$id Cache id
$metadonnees
array
$metadatas Associative array

Returns

boolean
True if no problem
protected string
# getNomFichierMeta( string $id )

Make and return a file name (with path) for metadatas

Make and return a file name (with path) for metadatas

Parameters

$id
string
$id Cache id

Returns

string
Metadatas file name (with path)
protected boolean
# etreFichierMeta( string $fichier_nom )

Check if the given filename is a metadatas one

Check if the given filename is a metadatas one

Parameters

$fichier_nom
string
$fileName File name

Returns

boolean
True if it's a metadatas one
protected boolean
# supprimerFichier( string $fichier )

Remove a file

Remove a file

If we can't remove the file (because of locks or any problem), we will touch the file to invalidate it

Parameters

$fichier
string
$file Complete file path

Returns

boolean
True if ok
protected boolean
# nettoyerFichiers( string $dossier, string $mode = Cache::NETTOYAGE_MODE_TOUS, array $tags = array() )

Clean some cache records (protected method used for recursive stuff)

Clean some cache records (protected method used for recursive stuff)

Available modes are : Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used) Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used) Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags ($tags can be an array of strings or a single string) Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags} ($tags can be an array of strings or a single string) Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags ($tags can be an array of strings or a single string)

Parameters

$dossier
string
$dir Directory to clean
$mode
string
$mode Clean mode
$tags
array
$tags Array of tags

Returns

boolean
True if no problem

Throws

Zend_Cache_Exception
protected
# analyserCache( mixed $dossier, mixed $mode, mixed $tags = array() )
protected string
# genererCleSecu( string $donnees, string $type_de_controle )

Make a control key with the string containing datas

Make a control key with the string containing datas

Parameters

$donnees
string
$data Data
$type_de_controle
string
$controlType Type of control 'md5', 'crc32' or 'strlen'

Returns

string
Control key

Throws

Zend_Cache_Exception
protected string
# transformaterIdEnNomFichier( string $id )

Transform a cache id into a file name and return it

Transform a cache id into a file name and return it

Parameters

$id
string
$id Cache id

Returns

string
File name
protected string
# getFichierNom( string $id )

Make and return a file name (with path)

Make and return a file name (with path)

Parameters

$id
string
$id Cache id

Returns

string
File name (with path)
protected string
# getChemin( string $id, boolean $decoupage = false )

Return the complete directory path of a filename (including hashedDirectoryStructure)

Return the complete directory path of a filename (including hashedDirectoryStructure)

Parameters

$id
string
$id Cache id
$decoupage
boolean
$decoupage if true, returns array of directory parts instead of single string

Returns

string
Complete directory path
protected boolean
# lancerMkdirEtChmodRecursif( string $id )

Make the directory strucuture for the given id

Make the directory strucuture for the given id

Parameters

$id
string
$id cache id

Returns

boolean
true
protected boolean|mixed
# testerExistenceCache( string $id, boolean $ne_pas_tester_validiter_du_cache )

Test if the given cache id is available (and still valid as a cache record)

Test if the given cache id is available (and still valid as a cache record)

Parameters

$id
string
$id Cache id
$ne_pas_tester_validiter_du_cache
boolean
$doNotTestCacheValidity If set to true, the cache validity won't be tested

Returns

boolean|mixed
false (a cache is not available) or "last modified" timestamp (int) of the available cache record
protected string
# getContenuFichier( string $fichier )

Return the file content of the given file

Return the file content of the given file

Parameters

$fichier
string
$file File complete path

Returns

string
File content (or false if problem)
protected boolean
# setContenuFichier( string $fichier, string $chaine )

Put the given string into the given file

Put the given string into the given file

Parameters

$fichier
string
$file File complete path
$chaine
string
$string String to put in file

Returns

boolean
true if no problem
protected string
# transformerNomFichierEnId( string $nom_de_fichier )

Transform a file name into cache id and return it

Transform a file name into cache id and return it

Parameters

$nom_de_fichier
string
$fileName File name

Returns

string
Cache id
Properties summary
protected array $options array( 'stockage_chemin' => null, 'fichier_verrou' => true, 'controle_lecture' => true, 'controle_lecture_type' => 'crc32', 'dossier_niveau' => 0, 'dossier_umask' => 0700, 'fichier_prefixe' => 'tbf', 'fichier_umask' => 0600, 'metadonnees_max_taille' => 100 )
#

Options disponibles

Options disponibles

> (string) stockage_chemin :

Chemin vers le dossier devant contenir l'arborescence du cache.

> (boolean) fichier_verrou :

  • Active / Désactive le verrouillage des fichiers
  • Peut éviter la corruption du cache dans de mauvaises circonstances, mais cela ne fonctionne pas sur des serveur

multithread et sur les systèmes de fichiers NFS par exemple.

> (boolean) controle_lecture :

  • Activer / désactiver le contrôle de lecture
  • S'il est activé, une clé de contrôle est ajoutée dans le fichier de cache et cette clé est comparée avec celle calculée

après la lecture.

> (string) controle_lecture_type :

Type de contrôle de lecture (seulement si le contrôle de lecture est activé). Les valeurs disponibles sont:

  • «md5» pour un contrôle md5 (le meilleur mais le plus lent)
  • «crc32» pour un contrôle de hachage crc32 (un peu moins sécurisé, mais plus rapide, un meilleur choix)
  • «adler32» pour un contrôle de hachage adler32 (excellent choix aussi, plus rapide que crc32)
  • «strlen» pour un test de longueur uniquement (le plus rapide)

> (int) dossier_niveau :

  • Permet de réglez le nombre de niveau de sous-dossier que contiendra l'arborescence des dossiers du cache.

0 signifie "pas de sous-dossier pour le cache", 1 signifie "un niveau de sous-dossier", 2 signifie "deux niveaux" ... Cette option peut accélérer le cache seulement lorsque vous avez plusieurs centaines de fichiers de cache. Seuls des tests spécifiques peuvent vous aider à choisir la meilleure valeur possible pour vous. 1 ou 2 peut être est un bon début.

> (int) dossier_umask :

  • Umask pour les sous-dossiers de l'arborescence du cache.

> (string) fichier_prefixe :

  • préfixe pour les fichiers du cache
  • ATTENTION : faite vraiment attention avec cette option, car une valeur trop générique dans le dossier cache du système

(comme /tmp) peut provoquer des catastrophes lors du nettoyage du cache.

> (int) fichier_umask :

  • Umask pour les fichiers de cache

> (int) metadonnees_max_taille :

  • taille maximum pour le tableau de métadonnées du cache (ne changer pas cette valeur sauf si vous savez ce que vous faite)
protected array $metadonnees array()
#

Array of metadatas (each item is an associative array)

Array of metadatas (each item is an associative array)

TBFramework - v0.3 API documentation generated by ApiGen 2.8.0