mirror of
https://github.com/pierre42100/ComunicWeb
synced 2025-06-19 12:25:16 +00:00
Added cache system
This commit is contained in:
88
assets/js/common/cacheManager.js
Normal file
88
assets/js/common/cacheManager.js
Normal file
@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Global cache management system
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
ComunicWeb.common.cacheManager = {
|
||||
/**
|
||||
* @var {Array} cachesArray An array that contains all the functions that can empty caches
|
||||
*/
|
||||
__cachesCleaners: [],
|
||||
|
||||
/**
|
||||
* @var {Array} intervalsList A list of all created intervals
|
||||
*/
|
||||
__intervalsList: [],
|
||||
|
||||
/**
|
||||
* Register a new cache cleaner
|
||||
*
|
||||
* @param {Function} cacheCleaner The cache cleaner to register
|
||||
* @param {Boolean} persistant If it is set to true, the cache will have to be cleaned only on user logout
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
registerCacheCleaner: function(cacheCleaner, persistant){
|
||||
|
||||
//Add the function to the list
|
||||
this.__cachesCleaners.push([cacheCleaner, persistant]);
|
||||
|
||||
//Success
|
||||
return true;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Register a new interval
|
||||
*
|
||||
* @param {Interval} interval The interval to register
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
registerInterval: function(interval){
|
||||
//Add the interval to the list
|
||||
this.__intervalsList.push(interval);
|
||||
|
||||
//Success
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Clean the caches
|
||||
*
|
||||
* @param {Boolean} allCaches Specify wether persistent caches has to be cleaned or not
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
cleanCaches: function(allCaches){
|
||||
|
||||
//Log action
|
||||
ComunicWeb.debug.logMessage("Empty all caches");
|
||||
|
||||
//Process each cleaning function
|
||||
for(i in this.__cachesCleaners){
|
||||
if(allCaches || !this.__cachesCleaners[i][1])
|
||||
eval(this.__cachesCleaners[i][0]+"()");
|
||||
}
|
||||
|
||||
//Success
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Unset all intervals
|
||||
*
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
cleanIntervals: function(){
|
||||
//Log action
|
||||
ComunicWeb.debug.logMessage("Unset all intervals");
|
||||
|
||||
//Process each cleaning function
|
||||
for(i in this.__intervalsList){
|
||||
//if(allCaches || !this.__intervalsList[i][1])
|
||||
clearInterval(this.__intervalsList[i]);
|
||||
}
|
||||
|
||||
//Success
|
||||
return true
|
||||
}
|
||||
}
|
@ -30,12 +30,17 @@ var ComunicWeb = {
|
||||
/**
|
||||
* Initializate the application
|
||||
*/
|
||||
init: function(){},
|
||||
init: function(openPage){},
|
||||
|
||||
/**
|
||||
* Restart the application
|
||||
*/
|
||||
restart: function(){},
|
||||
|
||||
/**
|
||||
* Reset the application
|
||||
*/
|
||||
reset: function(complete, openPage){},
|
||||
},
|
||||
|
||||
/**
|
||||
@ -48,6 +53,13 @@ var ComunicWeb = {
|
||||
makeAPIrequest: function(apiURI, params, requireLoginTokens, nextAction){},
|
||||
},
|
||||
|
||||
/**
|
||||
* Global cache management system
|
||||
*/
|
||||
cacheManager:{
|
||||
//TODO : implement
|
||||
},
|
||||
|
||||
/**
|
||||
* Langs functions
|
||||
*/
|
||||
@ -203,6 +215,11 @@ var ComunicWeb = {
|
||||
*/
|
||||
getRequest: function(url, cache, GETnextAction){},
|
||||
|
||||
/**
|
||||
* Empty network cache
|
||||
*/
|
||||
emptyCache: function(){},
|
||||
|
||||
/**
|
||||
* Update the status of the network
|
||||
*/
|
||||
@ -372,6 +389,11 @@ var ComunicWeb = {
|
||||
* Given user IDs (in an array) the function return their names in a string
|
||||
*/
|
||||
getNames: function(usersID, afterNames){},
|
||||
|
||||
/**
|
||||
* Empty users cache
|
||||
*/
|
||||
emptyCache: function(){},
|
||||
},
|
||||
},
|
||||
|
||||
@ -481,14 +503,14 @@ var ComunicWeb = {
|
||||
* Friends list caching system
|
||||
*/
|
||||
list:{
|
||||
|
||||
//TODO : implement
|
||||
},
|
||||
|
||||
/**
|
||||
* Friends bar
|
||||
*/
|
||||
bar:{
|
||||
|
||||
//TODO : implement
|
||||
},
|
||||
},
|
||||
|
||||
@ -514,13 +536,22 @@ var ComunicWeb = {
|
||||
* Conversations windows manager
|
||||
*/
|
||||
windows:{
|
||||
|
||||
//TODO : implement
|
||||
},
|
||||
|
||||
/**
|
||||
* Interface between conversation UI and the API
|
||||
*/
|
||||
interface:{},
|
||||
interface:{
|
||||
//TODO : implement
|
||||
},
|
||||
|
||||
/**
|
||||
* Opened conversations caching system
|
||||
*/
|
||||
cachingOpened:{
|
||||
//TODO : implement
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -64,6 +64,18 @@ ComunicWeb.common.network = {
|
||||
xhrRequest.send(null);
|
||||
},
|
||||
|
||||
/**
|
||||
* Empty network cache
|
||||
*
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
emptyCache: function(){
|
||||
this.cache = {};
|
||||
|
||||
//Success
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the status of the network
|
||||
*
|
||||
@ -102,5 +114,5 @@ ComunicWeb.common.network = {
|
||||
//Make sure the error message is visible on the screen
|
||||
byId("networkErrorMessage").style.display = "block";
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
@ -47,7 +47,7 @@ ComunicWeb.common.page = {
|
||||
this.emptyPage();
|
||||
|
||||
//Log message
|
||||
ComunicWeb.debug.logMessage("Display a wait splash screen the screen.");
|
||||
ComunicWeb.debug.logMessage("Display a wait splash screen on the screen.");
|
||||
|
||||
//Create message element (if required)
|
||||
if(message){
|
||||
|
@ -8,9 +8,10 @@ ComunicWeb.common.system = {
|
||||
/**
|
||||
* Initializate the application
|
||||
*
|
||||
* @param {String} Specify a page to open
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
init: function(){
|
||||
init: function(openPage){
|
||||
|
||||
//Display Comunic logo
|
||||
ComunicWeb.debug.displayComunicLogo();
|
||||
@ -30,7 +31,7 @@ ComunicWeb.common.system = {
|
||||
ComunicWeb.common.page.emptyPage();
|
||||
|
||||
//Show a wait splash screen
|
||||
ComunicWeb.common.page.showWaitSplashScreen();
|
||||
ComunicWeb.common.page.showWaitSplashScreen("Starting up...");
|
||||
|
||||
/**
|
||||
* Language initator
|
||||
@ -45,11 +46,16 @@ ComunicWeb.common.system = {
|
||||
/**
|
||||
* Open a page
|
||||
*/
|
||||
//Get current page URI
|
||||
var currentPage = ComunicWeb.common.url.getCurrentWebsiteURL();
|
||||
if(!openPage){
|
||||
//Get current page URI
|
||||
var currentPage = ComunicWeb.common.url.getCurrentWebsiteURL();
|
||||
|
||||
//Open a page
|
||||
ComunicWeb.common.page.openPage(currentPage);
|
||||
//Open a page
|
||||
ComunicWeb.common.page.openPage(currentPage);
|
||||
}
|
||||
else
|
||||
//Open specified page
|
||||
ComunicWeb.common.page.openPage(openPage);
|
||||
|
||||
//End of init
|
||||
ComunicWeb.debug.logMessage("Application is ready !");
|
||||
@ -66,8 +72,9 @@ ComunicWeb.common.system = {
|
||||
var autoRefresh = setInterval((function(){
|
||||
ComunicWeb.user.userLogin.refreshLoginState();
|
||||
}), 20000);
|
||||
ComunicWeb.common.cacheManager.registerInterval(autoRefresh);
|
||||
|
||||
//Sucess
|
||||
//Success
|
||||
return true;
|
||||
},
|
||||
|
||||
@ -82,5 +89,29 @@ ComunicWeb.common.system = {
|
||||
|
||||
//Reload the page
|
||||
location.href = document.location;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Reset the application
|
||||
*
|
||||
* @param {Boolean} complete Specify wether the cache cleaning has to be complete or not (for logout)
|
||||
* @param {String} openPage Specify a page to open once the application is restarted
|
||||
* @return {Boolean} True for a success
|
||||
*/
|
||||
reset: function(complete, openPage){
|
||||
//Show a wait splashscreen message
|
||||
ComunicWeb.common.page.showWaitSplashScreen("Reset the application in progress...");
|
||||
|
||||
//Clear intervals
|
||||
ComunicWeb.common.cacheManager.cleanIntervals();
|
||||
|
||||
//Clean caches
|
||||
ComunicWeb.common.cacheManager.cleanCaches(complete);
|
||||
|
||||
//Init the page again
|
||||
this.init(openPage);
|
||||
|
||||
//Success
|
||||
return true;
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user