Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 851 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 851 Rev 877
1
<?php
1
<?php
2
class CacheEflore {
2
class CacheEflore {
3
 
3
 
4
	private $service;
4
	private $service;
5
	private $config;
5
	private $config;
6
	private $dureecache = 0;
6
	private $dureecache = 0;
7
	private $projetNom;
7
	private $projetNom;
8
	private $serviceNom;
8
	private $serviceNom;
9
	private $cache;
9
	private $cache;
10
	private $cacheActif;
10
	private $cacheActif;
11
 
11
 
12
	public function __construct($service, $projetNom, $serviceNom, $cacheActif) {
12
	public function __construct($service, $projetNom, $serviceNom, $cacheActif) {
13
		$this->cacheActif = $cacheActif;
13
		$this->cacheActif = $cacheActif;
14
		$this->service = $service;
14
		$this->service = $service;
15
		$this->chargerDureeCache();
15
		$this->chargerDureeCache();
16
		$this->projetNom = $projetNom;
16
		$this->projetNom = $projetNom;
17
		$this->serviceNom = $serviceNom;
17
		$this->serviceNom = $serviceNom;
18
		$this->cache = new CacheSimple(array(
18
		$this->cache = new CacheSimple(array(
19
			"mise_en_cache" => true, 
19
			"mise_en_cache" => true, 
20
			"stockage_chemin" => Config::get('chemin_cache').'services'.DS, 
20
			"stockage_chemin" => Config::get('chemin_cache').'services'.DS, 
21
			"duree_de_vie" => $this->dureecache));
21
			"duree_de_vie" => $this->dureecache));
22
	}
22
	}
23
 
23
 
24
	public function chargerDureeCache() {
24
	public function chargerDureeCache() {
25
		if ($this->cacheActif == "1") {
25
		if ($this->cacheActif == "1") {
26
			$this->dureecache = Commun::getDureeCache();
26
			$this->dureecache = Commun::getDureeCache();
27
		}
27
		}
28
	}
28
	}
29
 
29
 
30
	public function consulter() {
30
	public function consulter() {
31
		list($ressources, $parametres) = func_get_args();
31
		list($ressources, $parametres) = func_get_args();
-
 
32
		$args = func_get_args(); // XXX: PHP-5.3
32
		$id = $this->genererID($ressources, $parametres);
33
		$id = $this->genererID($ressources, $parametres);
33
		$retour = unserialize($this->cache->charger($id));
34
		$retour = unserialize($this->cache->charger($id));
34
		if ($retour == false) {
35
		if ($retour == false) {
35
			$retour = call_user_func_array(array($this, 'mettreEnCache'),
36
			$retour = call_user_func_array(array($this, 'mettreEnCache'),
36
										   func_get_args());
37
										   $args);
37
		}
38
		}
38
 
39
 
39
		return $retour;
40
		return $retour;
40
	}
41
	}
41
 
42
 
42
	public function mettreEnCache() {
43
	public function mettreEnCache() {
43
		list($ressources, $parametres) = func_get_args();
44
		list($ressources, $parametres) = func_get_args();
-
 
45
		$args = func_get_args(); // XXX: PHP-5.3
44
		$retour = call_user_func_array(array($this->service, 'consulter'),
46
		$retour = call_user_func_array(array($this->service, 'consulter'),
45
									   func_get_args());
47
									   $args);
46
		$id = $this->genererID($ressources, $parametres);
48
		$id = $this->genererID($ressources, $parametres);
47
		if ($this->dureecache > 0) {
49
		if ($this->dureecache > 0) {
48
			$this->cache->sauver(serialize($retour), $id);
50
			$this->cache->sauver(serialize($retour), $id);
49
		}
51
		}
50
		return $retour;
52
		return $retour;
51
	}
53
	}
52
 
54
 
53
	public function genererID($ressources, $parametres) {
55
	public function genererID($ressources, $parametres) {
54
		$chaineRessources = "";
56
		$chaineRessources = "";
55
		$chaineParametres = "";
57
		$chaineParametres = "";
56
		if (count($ressources) > 0) {
58
		if (count($ressources) > 0) {
57
			foreach ($ressources as $key => $val) {
59
			foreach ($ressources as $key => $val) {
58
				$chaineRessources .= "$key:$val;";
60
				$chaineRessources .= "$key:$val;";
59
			}
61
			}
60
		}
62
		}
61
 
63
 
62
		if (count($parametres) > 0) {
64
		if (count($parametres) > 0) {
63
			foreach ($parametres as $key => $val) {
65
			foreach ($parametres as $key => $val) {
64
				$chaineParametres .= "$key:$val;";
66
				$chaineParametres .= "$key:$val;";
65
			}
67
			}
66
		}
68
		}
67
 
69
 
68
		$chaineMD5 = $this->projetNom.'/'.$this->serviceNom.'/'.md5($chaineRessources.$chaineParametres);
70
		$chaineMD5 = $this->projetNom.'/'.$this->serviceNom.'/'.md5($chaineRessources.$chaineParametres);
69
		return $chaineMD5;
71
		return $chaineMD5;
70
	}
72
	}
71
}
73
}
72
?>
74
?>