Added ability to read file data from Minify Cache, without writing to disk

This commit is contained in:
coderaiser 2012-07-10 09:07:02 -04:00
parent a95d07e6d8
commit cc31dc3b41
3 changed files with 48 additions and 16 deletions

View file

@ -12,4 +12,6 @@ return final_code so changes was not saving, and clien side loaded keyBinding.js
and cloudfunc.js full sized versions.
* Changed the way Minify post-processing js-files so, from now in Minify object
post-processing functions passed like this {'client.js': function(){}}
post-processing functions passed like this {'client.js': function(){}}
* Added ability to read file data from Minify Cache, without writing to disk

@ -1 +1 @@
Subproject commit 080b6e746f773649fd06aa113a2298fa285478c3
Subproject commit 04d536b9941088ef25294a03e0ca75047dd30131

View file

@ -189,7 +189,7 @@ CloudServer.Minify={
.replace('/lib/', lMinFolder)
.replace('/lib/client/', lMinFolder)).length);
return pFinalCode;
}})
}},true)
:false;
this.done.html=this._allowed.html?
@ -198,14 +198,17 @@ CloudServer.Minify={
this.done.css=this._allowed.css?
lMinify.cssStyles([CloudServer.CSSDIR + '/style.css',
CloudServer.CSSDIR + '/reset.css'],
this._allowed.img):false;
this._allowed.img):false;
this.Cache = lMinify.Cache;
}
}),
/* свойство показывающее случилась ли ошибка*/
done:{js: false,css: false, html:false},
/* minification folder name */
MinFolder:''
MinFolder :'',
Cache :{}
};
@ -276,7 +279,7 @@ CloudServer.init=(function(){
*/
CloudServer.Minify.setAllowed(CloudServer.Config.minification);
/* Если нужно минимизируем скрипты */
CloudServer.Minify.doit();
CloudServer.Minify.doit();
});
@ -435,18 +438,43 @@ CloudServer._controller=function(pReq, pRes)
* не сжатый - в обратном случае
*/
var lFileData=CloudServer.Cache.get(CloudServer.Gzip?(lName+'_gzip'):lName);
console.log(Path.basename(lName));
var lMinify=CloudServer.Minify;
/* object thet contains information
* about the source of file data
*/
var lFromCache_o={'cache': true};
/* if cache is empty and Cache allowed and Minify_allowed
* and in Minifys cache is files, so save it to
* CloudServer cache
*/
if(!lFileData &&
lMinify._allowed){
console.log('trying to read data from Minify.Cache');
lFromCache_o.cache=false;
lFileData = CloudServer.Minify.Cache[
Path.basename(lName)];
}
var lReadFileFunc_f=CloudServer.getReadFileFunc(lName);
/* если там что-то есть передаём данные в функцию
* readFile
*/
if(lFileData){
console.log('readed from cache');
if(lFileData){
/* if file readed not from cache - he readed from minified cache */
if(lFromCache_o.cache===false)
lFromCache_o.minify=true;
else
lFromCache_o.minify=false;
console.log(lName + ' readed from cache');
/* передаём данные с кэша,
* если gzip включен - сжатые
* в обратном случае - несжатые
*/
lReadFileFunc_f(undefined,lFileData,true);
lReadFileFunc_f(undefined,lFileData,lFromCache_o);
}
else Fs.readFile(lName,lReadFileFunc_f);
@ -674,11 +702,13 @@ CloudServer._readDir=function (pError, pFiles)
*/
CloudServer.getReadFileFunc = function(pName){
/*
* @pError - ошибка
* @pData - данные
* @pFromFile - прочитано с файла bool
* @pError - ошибка
* @pData - данные
* @pFromCache_o - прочитано с файла,
* или из одного из кешей
* Пример {cache: false, minify: true}
*/
var lReadFile=function(pError,pData,pFromCache_b){
var lReadFile=function(pError, pData, pFromCache_o){
if (!pError){
console.log('file ' + pName + ' readed');
@ -686,7 +716,7 @@ CloudServer.getReadFileFunc = function(pName){
* если их нет в кэше -
* сохраняем
*/
if(!pFromCache_b && CloudServer.Cache.isAllowed)
if(pFromCache_o && !pFromCache_o.cache && CloudServer.Cache.isAllowed)
CloudServer.Cache.set(pName,pData);
/* если кэш есть
* сохраняем его в переменную
@ -697,7 +727,7 @@ CloudServer.getReadFileFunc = function(pName){
var lHeader=CloudServer.generateHeaders(pName,CloudServer.Gzip);
/* если браузер поддерживает gzip-сжатие - сжимаем данные*/
if(CloudServer.Gzip &&!pFromCache_b){
if( CloudServer.Gzip && !(pFromCache_o && pFromCache_o.cache) ){
/* сжимаем содержимое */
Zlib.gzip(pData,CloudServer.getGzipDataFunc(lHeader,pName));
}