Subversion Repositories Applications.framework

Rev

Rev 271 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 271 Rev 272
Line 2... Line 2...
2
class ServiceCacheSqlite extends Service {
2
class ServiceCacheSqlite extends Service {
Line 3... Line 3...
3
	
3
	
4
	public function consulter($ressources, $parametres) {
4
	public function consulter($ressources, $parametres) {
5
		$options = array(
5
		$options = array(
6
			'stockage_mode'				 => Cache::STOCKAGE_MODE_SQLITE,
6
			'stockage_mode'				 => Cache::STOCKAGE_MODE_SQLITE,
7
			'stockage_chemin'				 => $this->getTmpDir(),
7
			'stockage_chemin'				 => Fichier::getDossierTmp(),
8
			'controle_ecriture'			 => false,
8
			'controle_ecriture'			 => false,
9
			'mise_en_cache'		  		 => true,
9
			'mise_en_cache'		  		 => true,
10
			'cache_id_prefixe'		  		 => null,
10
			'cache_id_prefixe'		  		 => null,
11
			'serialisation_auto'		  	 => false,
11
			'serialisation_auto'		  	 => false,
Line 80... Line 80...
80
			$cache->ajouterSupplementDureeDeVie($id_test, -3540);
80
			$cache->ajouterSupplementDureeDeVie($id_test, -3540);
81
			$meta02 = $cache->getMetadonnees($id_test);
81
			$meta02 = $cache->getMetadonnees($id_test);
82
			echo "Durée de vie du cache '$id_test' après ajout supplément de -3540s : ".$meta02['expiration'].
82
			echo "Durée de vie du cache '$id_test' après ajout supplément de -3540s : ".$meta02['expiration'].
83
				' - diff. : '.($meta02['expiration'] - $meta01['expiration']).'<br/>';
83
				' - diff. : '.($meta02['expiration'] - $meta01['expiration']).'<br/>';
84
		}
84
		}
85
	}
85
	}    
86
	
-
 
87
	/**
-
 
88
     * Determine system TMP directory and detect if we have read access
-
 
89
     *
-
 
90
     * inspired from Zend_File_Transfer_Adapter_Abstract & Zend_Cache
-
 
91
     *
-
 
92
     * @return string
-
 
93
     */
-
 
94
    public function getTmpDir() {
-
 
95
        $tmpdir = array();
-
 
96
        foreach (array($_ENV, $_SERVER) as $tab) {
-
 
97
            foreach (array('TMPDIR', 'TEMP', 'TMP', 'windir', 'SystemRoot') as $key) {
-
 
98
                if (isset($tab[$key])) {
-
 
99
                    if (($key == 'windir') or ($key == 'SystemRoot')) {
-
 
100
                        $dir = realpath($tab[$key] . '\\temp');
-
 
101
                    } else {
-
 
102
                        $dir = realpath($tab[$key]);
-
 
103
                    }
-
 
104
                    if ($this->isGoodTmpDir($dir)) {
-
 
105
                        return $dir;
-
 
106
                    }
-
 
107
                }
-
 
108
            }
-
 
109
        }
-
 
110
        $upload = ini_get('upload_tmp_dir');
-
 
111
        if ($upload) {
-
 
112
            $dir = realpath($upload);
-
 
113
            if ($this->isGoodTmpDir($dir)) {
-
 
114
                return $dir;
-
 
115
            }
-
 
116
        }
-
 
117
        if (function_exists('sys_get_temp_dir')) {
-
 
118
            $dir = sys_get_temp_dir();
-
 
119
            if ($this->isGoodTmpDir($dir)) {
-
 
120
                return $dir;
-
 
121
            }
-
 
122
        }
-
 
123
        // Attemp to detect by creating a temporary file
-
 
124
        $tempFile = tempnam(md5(uniqid(rand(), TRUE)), '');
-
 
125
        if ($tempFile) {
-
 
126
            $dir = realpath(dirname($tempFile));
-
 
127
            unlink($tempFile);
-
 
128
            if ($this->isGoodTmpDir($dir)) {
-
 
129
                return $dir;
-
 
130
            }
-
 
131
        }
-
 
132
        if ($this->isGoodTmpDir('/tmp')) {
-
 
133
            return '/tmp';
-
 
134
        }
-
 
135
        if ($this->isGoodTmpDir('\\temp')) {
-
 
136
            return '\\temp';
-
 
137
        }
-
 
138
    }
-
 
139
    
-
 
140
    /**
-
 
141
     * Verify if the given temporary directory is readable and writable
-
 
142
     *
-
 
143
     * @param $dir temporary directory
-
 
144
     * @return boolean true if the directory is ok
-
 
145
     */
-
 
146
    protected function isGoodTmpDir($dir){
-
 
147
        if (is_readable($dir)) {
-
 
148
            if (is_writable($dir)) {
-
 
149
                return true;
-
 
150
            }
-
 
151
        }
-
 
152
        return false;
-
 
153
    }
-
 
154
    
-
 
155
}
86
}
156
?>
87
?>
157
88