diff --git a/build/router/controller/page.php b/build/router/controller/page.php
index 138ca84..d5765d7 100644
--- a/build/router/controller/page.php
+++ b/build/router/controller/page.php
@@ -30,7 +30,7 @@
=========================================================*/
/* (1) Get config */
try{
- $config = Config::load("http://sciences.univ-pau.fr/edt/_ressource.js", "http://sciences.univ-pau.fr/edt/_periode.js");
+ $config = Config::loadCached();
/* (2) Error management */
}catch(\Exception $e){
@@ -44,17 +44,22 @@
/* [2] Display the links
=========================================================*/
+ echo "
Diplome | Link |
";
+
foreach($diplomes as $id=>$name){
- echo "$name";
+ echo "$name | ";
$link = $_SERVER['HTTP_HOST']."/ics/$id.ics";
if( file_exists(__ROOT__."/tmp/$id.ics") )
- echo " -> https://$link
";
+ echo "https://$link | ";
+ echo "
";
}
+ echo "
";
+
}
/* POST-CALL
diff --git a/build/service/Config.php b/build/service/Config.php
index 90cb220..09bc6b1 100644
--- a/build/service/Config.php
+++ b/build/service/Config.php
@@ -171,7 +171,60 @@
- /* [4] Return the instance
+ /* [4] Return the instance + cache
+ =========================================================*/
+ /* (1) Cache */
+ file_put_contents(__ROOT__."/tmp/diplomes.cache", json_encode($d_list));
+ file_put_contents(__ROOT__."/tmp/periods.cache", json_encode($p_list));
+
+ /* (2) Return the instance */
+ return new Config($d_list, $p_list);
+
+ }
+
+
+
+ /* (3) Loads the configuration from URL
+ *
+ * @return instance The created instance
+ * NULL on error
+ *
+ ---------------------------------------------------------*/
+ public static function loadCached(){
+
+ /* [1] Load cache
+ =========================================================*/ {
+
+ /* (1) Check files */
+ if( !file_exists(__ROOT__."/tmp/diplomes.cache") )
+ throw new \Exception("Diplomes cache is missing");
+
+ if( !file_exists(__ROOT__."/tmp/periods.cache") )
+ throw new \Exception("Periods cache is missing");
+
+
+ /* (2) Read files */
+ if( !($d_list=@file_get_contents(__ROOT__."/tmp/diplomes.cache")) )
+ throw new \Exception("Diplomes cache is not readable");
+
+ if( !($p_list=@file_get_contents(__ROOT__."/tmp/periods.cache")) )
+ throw new \Exception("Periods cache is not readable");
+
+
+ /* (3) Parse files */
+ if( is_null(( $d_list = json_decode($d_list, true) )) )
+ throw new \Exception("Cannot parse diplome list");
+
+ if( is_null(( $p_list = json_decode($p_list, true) )) )
+ throw new \Exception("Cannot parse periods list");
+
+
+ }
+
+
+
+
+ /* [2] Return the instance
=========================================================*/
return new Config($d_list, $p_list);
@@ -180,7 +233,7 @@
- /* (3) Getter diplomes
+ /* (4) Getter diplomes
*
* @return diplomes Diplome list
*
@@ -192,7 +245,7 @@
- /* (4) Getter periods
+ /* (5) Getter periods
*
* @return periods Period list
*