"Fossies" - the Fresh Open Source Software Archive

Member "ganglia-web-3.7.2/lib/Cache/Driver_Json.php" (12 Oct 2015, 1563 Bytes) of package /linux/www/ganglia-web-3.7.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Driver_Json.php" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.7.1_vs_3.7.2.

    1 <?php
    2 
    3 function g_cache_exists() {
    4     global $conf;
    5     return file_exists( $conf['cachefile'] );
    6 } // end function g_cache_exists
    7 
    8 function g_cache_serialize($data) {
    9     global $conf;
   10     file_put_contents($conf['cachefile'], json_encode($data));
   11     file_put_contents($conf['cachefile'] . "_cluster_data", json_encode($data["cluster"]));
   12     file_put_contents($conf['cachefile'] . "_host_list", json_encode($data["hosts"]));
   13     file_put_contents($conf['cachefile'] . "_metric_list", json_encode(array_keys($data["metrics"])));
   14 } // end function g_cache_serialize
   15 
   16 function g_cache_deserialize($index) {
   17     global $conf;
   18         $index_array = array();
   19     
   20         switch ( $index ) {
   21 
   22            case "hosts_and_metrics":
   23            $index_array["cluster"] = json_decode(file_get_contents($conf['cachefile'] . "_cluster_data"), TRUE);
   24            $index_array["hosts"] = json_decode(file_get_contents($conf['cachefile'] . "_host_list"), TRUE);
   25            $index_array["metrics"] = json_decode(file_get_contents($conf['cachefile'] . "_metric_list"), TRUE);
   26                break;
   27         
   28            case "metric_list":
   29            $index_array["metric_list"] = json_decode(file_get_contents($conf['cachefile'] . "_" . $index), TRUE);
   30                break;
   31 
   32            default:
   33            $index_array = json_decode(file_get_contents($conf['cachefile']), TRUE);
   34              
   35         }
   36     return $index_array;
   37 } // end function g_cache_deserialize
   38 
   39 function g_cache_expire () {
   40     global $conf;
   41     $time_diff = time() - filemtime($conf['cachefile']);
   42     return $time_diff;
   43 } // end function g_cache_expire
   44 
   45 ?>