Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 670 Rev 693
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(
-
 
19
			"mise_en_cache" => true, 
18
		$this->cache = new CacheSimple(array("mise_en_cache" => true, "stockage_chemin" => Config::get("chemincache"), "duree_de_vie" => $this->dureecache));
20
			"stockage_chemin" => Config::get('chemin_cache').'services'.DS, 
-
 
21
			"duree_de_vie" => $this->dureecache));
19
	}
22
	}
20
 
23
 
21
	public function chargerDureeCache() {
24
	public function chargerDureeCache() {
22
		if ($this->cacheActif == "1") {
25
		if ($this->cacheActif == "1") {
23
			$this->dureecache = $this->service->getDureeCache();
26
			$this->dureecache = $this->service->getDureeCache();
24
		}
27
		}
25
	}
28
	}
26
 
29
 
27
	public function consulter($ressources, $parametres) {
30
	public function consulter($ressources, $parametres) {
28
		$id = $this->genererID($ressources, $parametres);
31
		$id = $this->genererID($ressources, $parametres);
29
		$retour = unserialize($this->cache->charger($id));
32
		$retour = unserialize($this->cache->charger($id));
30
		if ($retour == false) {
33
		if ($retour == false) {
31
			$retour = $this->mettreEnCache($ressources, $parametres);
34
			$retour = $this->mettreEnCache($ressources, $parametres);
32
		}
35
		}
33
 
36
 
34
		return $retour;
37
		return $retour;
35
	}
38
	}
36
 
39
 
37
	public function mettreEnCache($ressources, $parametres) {
40
	public function mettreEnCache($ressources, $parametres) {
38
		$retour = $this->service->consulter($ressources, $parametres);
41
		$retour = $this->service->consulter($ressources, $parametres);
39
		$id = $this->genererID($ressources, $parametres);
42
		$id = $this->genererID($ressources, $parametres);
40
		if ($this->dureecache > 0) {
43
		if ($this->dureecache > 0) {
41
			$this->cache->sauver(serialize($retour), $id);
44
			$this->cache->sauver(serialize($retour), $id);
42
		}
45
		}
43
		return $retour;
46
		return $retour;
44
	}
47
	}
45
 
48
 
46
	public function genererID($ressources, $parametres) {
49
	public function genererID($ressources, $parametres) {
47
		$chaineRessources = "";
50
		$chaineRessources = "";
48
		$chaineParametres = "";
51
		$chaineParametres = "";
49
		if (count($ressources) > 0) {
52
		if (count($ressources) > 0) {
50
			foreach ($ressources as $key => $val) {
53
			foreach ($ressources as $key => $val) {
51
				$chaineRessources .= "$key:$val;";
54
				$chaineRessources .= "$key:$val;";
52
			}
55
			}
53
		}
56
		}
54
 
57
 
55
		if (count($parametres) > 0) {
58
		if (count($parametres) > 0) {
56
			foreach ($parametres as $key => $val) {
59
			foreach ($parametres as $key => $val) {
57
				$chaineParametres .= "$key:$val;";
60
				$chaineParametres .= "$key:$val;";
58
			}
61
			}
59
		}
62
		}
60
 
63
 
61
		$chaineMD5 = $this->projetNom.'/'.$this->serviceNom.'/'.md5($chaineRessources.$chaineParametres);
64
		$chaineMD5 = $this->projetNom.'/'.$this->serviceNom.'/'.md5($chaineRessources.$chaineParametres);
62
		return $chaineMD5;
65
		return $chaineMD5;
63
	}
66
	}
64
}
67
}
65
?>
68
?>