Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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