fixed cache, use files as cache instead of database, minor fixes

This commit is contained in:
Ulf Gebhardt 2017-03-31 20:38:57 +02:00
parent 749e079645
commit 41e82faa64
8 changed files with 66 additions and 18 deletions

13
cache/cache.php vendored
View File

@ -27,13 +27,16 @@ class cache {
$result = \SYSTEM\SQL\SYS_CACHE_CHECK::Q1(array($cache,$ident)); $result = \SYSTEM\SQL\SYS_CACHE_CHECK::Q1(array($cache,$ident));
if(!$result){ if(!$result){
return NULL;} return NULL;}
if(!file_exists($result['data'])){
return NULL;}
if($header){ if($header){
if(\SYSTEM\HEADER::available($result['type'])){ if(\SYSTEM\HEADER::available($result['type'])){
call_user_func('\SYSTEM\HEADER::'.$result['type']); call_user_func('\SYSTEM\HEADER::'.$result['type']);
}else{ }else{
\SYSTEM\HEADER::FILE($ident);} \SYSTEM\HEADER::FILE($ident);}
} }
return $result['cache'] == \SYSTEM\CACHE\cache_filemask::CACHE_FILEMASK ? \file_get_contents($result['data']) : $result['data']; return \file_get_contents($result['data']);
} }
/** /**
@ -50,7 +53,13 @@ class cache {
if(($fail_on_exist && self::get($cache,$ident) != NULL)){ if(($fail_on_exist && self::get($cache,$ident) != NULL)){
return NULL;} return NULL;}
$result = \SYSTEM\SQL\SYS_CACHE_PUT::Q1(array($cache,$ident, $type, $data)); $path = \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_CACHE).$ident;
$file = \fopen($path, "w");
\fwrite($file, $data);
\fclose($file);
$result = \SYSTEM\SQL\SYS_CACHE_PUT::Q1(array($cache,$ident, $type, $path));
return $result ? $data : NULL; return $result ? $data : NULL;
} }

19
cache/cache_css.php vendored
View File

@ -57,7 +57,24 @@ class cache_css {
* @param array $files List of Files to be cached into one Cacheentry * @param array $files List of Files to be cached into one Cacheentry
* @return url Returns the requested Cache-URL * @return url Returns the requested Cache-URL
*/ */
public static function url($files){ /*public static function url($files){
$ident = self::ident($files);
if(!\SYSTEM\CACHE\cache_css::get($ident)){
\LIB\lib_minify::php();
$minifier = new \MatthiasMullie\Minify\CSS();
foreach($files as $f){
$minifier->add($f->SERVERPATH());}
\SYSTEM\CACHE\cache_css::put($ident, $minifier->minify());}
return './api.php?call=cache&id='.self::CACHE_CSS.'&ident='.$ident;
}*/
/**
* Minify CSS and calculate URL from it
*
* @param array $files List of Files to be cached into one Cacheentry
* @return url Returns the requested Cache-URL
*/
public static function minify($files){
$ident = self::ident($files); $ident = self::ident($files);
if(!\SYSTEM\CACHE\cache_css::get($ident)){ if(!\SYSTEM\CACHE\cache_css::get($ident)){
\LIB\lib_minify::php(); \LIB\lib_minify::php();

View File

@ -28,7 +28,7 @@ class cache_filemask {
public static function put($file){ public static function put($file){
$ext = pathinfo($file); $ext = pathinfo($file);
$ext = strtoupper(array_key_exists('extension', $ext) ? $ext['extension'] : ''); $ext = strtoupper(array_key_exists('extension', $ext) ? $ext['extension'] : '');
return \SYSTEM\CACHE\cache::put(self::CACHE_FILEMASK, self::ident($file), $ext ,$file);} return \SYSTEM\CACHE\cache::put(self::CACHE_FILEMASK, self::ident($file), $ext ,file_get_contents($file));}
/** /**
* Get Data from Cache * Get Data from Cache

19
cache/cache_js.php vendored
View File

@ -57,7 +57,24 @@ class cache_js {
* @param array $files List of Files to be cached into one Cacheentry * @param array $files List of Files to be cached into one Cacheentry
* @return url Returns the requested Cache-URL * @return url Returns the requested Cache-URL
*/ */
public static function url($files){ /*public static function url($files){
$ident = self::ident($files);
if(!\SYSTEM\CACHE\cache_js::get($ident)){
\LIB\lib_minify::php();
$minifier = new \MatthiasMullie\Minify\JS();
foreach($files as $f){
$minifier->add($f->SERVERPATH());}
\SYSTEM\CACHE\cache_js::put($ident, $minifier->minify());}
return './api.php?call=cache&id='.self::CACHE_JS.'&ident='.$ident;
}*/
/**
* Minify JS files and calculate URL for it
*
* @param array $files List of Files to be cached into one Cacheentry
* @return url Returns the requested Cache-URL
*/
public static function minify($files){
$ident = self::ident($files); $ident = self::ident($files);
if(!\SYSTEM\CACHE\cache_js::get($ident)){ if(!\SYSTEM\CACHE\cache_js::get($ident)){
\LIB\lib_minify::php(); \LIB\lib_minify::php();

View File

@ -56,6 +56,10 @@ class config_ids {
/** int Logextraction path used by the Application */ /** int Logextraction path used by the Application */
const SYS_CRON_LOG2SQLITE_PATH = 30; const SYS_CRON_LOG2SQLITE_PATH = 30;
/** int Cache path used by the Application */
const SYS_CONFIG_PATH_CACHE = 31;
/** int Projectname of the Application */ /** int Projectname of the Application */
const SYS_SAI_CONFIG_PROJECT = 54; const SYS_SAI_CONFIG_PROJECT = 54;
} }

View File

@ -53,7 +53,7 @@ class State {
$row['css'] = $row['js'] = array(); $row['css'] = $row['js'] = array();
if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'css') && \is_callable($row['php_class'].'::css')){ if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'css') && \is_callable($row['php_class'].'::css')){
$row['css'] = array_merge($row['css'], \call_user_func($row['php_class'].'::css'));} $row['css'] = array_merge($row['css'], \call_user_func($row['php_class'].'::css'));}
$row['css'] = count($row['css']) > 0 ? array(\SYSTEM\CACHE\cache_css::url($row['css'])) : array(); $row['css'] = count($row['css']) > 0 ? array(\SYSTEM\CACHE\cache_css::minify($row['css'])) : array();
if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'scss') && \is_callable($row['php_class'].'::scss')){ if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'scss') && \is_callable($row['php_class'].'::scss')){
$scss = \call_user_func($row['php_class'].'::scss'); $scss = \call_user_func($row['php_class'].'::scss');
foreach($scss as $s){ foreach($scss as $s){
@ -61,7 +61,7 @@ class State {
} }
if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'js') && \is_callable($row['php_class'].'::js')){ if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'js') && \is_callable($row['php_class'].'::js')){
$row['js'] = array_merge($row['js'], \call_user_func($row['php_class'].'::js'));} $row['js'] = array_merge($row['js'], \call_user_func($row['php_class'].'::js'));}
$row['js'] = count($row['js']) > 0 ? array(\SYSTEM\CACHE\cache_js::url($row['js'])) : array(); $row['js'] = count($row['js']) > 0 ? array(\SYSTEM\CACHE\cache_js::minify($row['js'])) : array();
if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'title') && \is_callable($row['php_class'].'::title')){ if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'title') && \is_callable($row['php_class'].'::title')){
$row['title'] = \call_user_func($row['php_class'].'::title');} $row['title'] = \call_user_func($row['php_class'].'::title');}
if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'meta') && \is_callable($row['php_class'].'::meta')){ if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'meta') && \is_callable($row['php_class'].'::meta')){

View File

@ -66,9 +66,9 @@ class default_page implements \SYSTEM\PAGE\DefaultPage {
*/ */
public static function css(){ public static function css(){
return \SYSTEM\HTML\html::link(\LIB\lib_bootstrap::css()->WEBPATH(false)). return \SYSTEM\HTML\html::link(\LIB\lib_bootstrap::css()->WEBPATH(false)).
\SYSTEM\HTML\html::link(\LIB\lib_tablesorter::css()->WEBPATH(false)). \SYSTEM\HTML\html::link(\SYSTEM\CACHE\cache_css::minify(
\SYSTEM\HTML\html::link(\SYSTEM\CACHE\cache_css::url( array( \LIB\lib_tablesorter::css(),
array( \LIB\lib_system::css(), \LIB\lib_system::css(),
new \SYSTEM\PSAI('page/css/sai_classes.css'), new \SYSTEM\PSAI('page/css/sai_classes.css'),
new \SYSTEM\PSAI('page/css/sai.css')))); new \SYSTEM\PSAI('page/css/sai.css'))));
} }
@ -79,13 +79,13 @@ class default_page implements \SYSTEM\PAGE\DefaultPage {
* @return string Returns html of the Sai js includes * @return string Returns html of the Sai js includes
*/ */
public static function js(){ public static function js(){
return \SYSTEM\HTML\html::script(\LIB\lib_jquery::js()->WEBPATH()). return \SYSTEM\HTML\html::script( \SYSTEM\CACHE\cache_js::minify(
\SYSTEM\HTML\html::script(\LIB\lib_bootstrap::js()->WEBPATH()). array( \LIB\lib_jquery::js(),
\SYSTEM\HTML\html::script(\LIB\lib_tablesorter::js()->WEBPATH()). \LIB\lib_bootstrap::js(),
\SYSTEM\HTML\html::script(\LIB\lib_bootstrap_growl::js()->WEBPATH()). \LIB\lib_tablesorter::js(),
\SYSTEM\HTML\html::script(\LIB\lib_tinymce::js()->WEBPATH(false)). \LIB\lib_bootstrap_growl::js(),
\SYSTEM\HTML\html::script( \SYSTEM\CACHE\cache_js::url( \LIB\lib_tinymce::js(),
array( \LIB\lib_system::js(), \LIB\lib_system::js(),
new \SYSTEM\PSAI('page/js/sai.js')))). new \SYSTEM\PSAI('page/js/sai.js')))).
\SYSTEM\HTML\html::script('https://www.google.com/jsapi'). \SYSTEM\HTML\html::script('https://www.google.com/jsapi').
'<script type="text/javascript">google.load("visualization", "1", {packages:["corechart"]});</script>'; '<script type="text/javascript">google.load("visualization", "1", {packages:["corechart"]});</script>';

View File

@ -92,6 +92,7 @@ class HEADER {
*/ */
public static function JS(){ public static function JS(){
if(self::checkHeader()){ if(self::checkHeader()){
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 7))); // 1 week
header('content-type:application/javascript;');}} header('content-type:application/javascript;');}}
/** /**
* Send CSS Headers, if Header was not sent yet * Send CSS Headers, if Header was not sent yet