1 /*******************************************************************************
2 * Copyright � Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
3 * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Alexandre Lefevre, Marc Salvat 2014-2016
4 * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Marc Salvat, Marc Suarez, Harifetra Ramamonjy 2017
6 * This file is part of the work and learning management system Pentila Nero.
8 * Pentila Nero is free software. You can redistribute it and/or modify since
9 * you respect the terms of either (at least one of the both license) :
10 * - under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 * - the CeCILL-C as published by CeCILL-C; either version 1 of the
14 * License, or any later version
15 * - the GNU Lesser General Public License as published by the
16 * Free Software Foundation, either version 3 of the license,
17 * or (at your option) any later version.
19 * There are special exceptions to the terms and conditions of the
20 * licenses as they are applied to this software. View the full text of
21 * the exception in file LICENSE-PROJECT.txt in the directory of this software
24 * Pentila Nero is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * Licenses for more details.
29 * You should have received a copy of the GNU Affero General Public License
30 * and the CeCILL-C and the GNU Lesser General Public License along with
31 * Pentila Nero. If not, see :
32 * <http://www.gnu.org/licenses/> and
33 * <http://www.cecill.info/licences.fr.html>.
34 ******************************************************************************/
35 package com.pentila.entSavoie.utils;
38 import com.whirlycott.cache.*;
40 public class ENTCacheUtils {
42 //define whirlycache Cache object
43 static Cache whirlycache=null;
45 //initialize whirlycache's cache instance
48 whirlycache=CacheManager.getInstance().getCache();
49 } catch (com.whirlycott.cache.CacheException e) {
54 //check logic whether the Cache instance is initialized properly or not and
55 //cache key is eligible or not.
56 private static boolean checkCache(String pKey){
57 if(whirlycache==null){
60 if(pKey==null || pKey.equals("")){
66 //get object from cache instance based on specified argument value.
67 public static Object getObjectFromCache(String pKey){
68 if(checkCache(pKey)==false){
71 return whirlycache.retrieve(pKey);
74 //invalid object from cache instance based on specified argument value.
75 public static Object removeObjectFromCache(String pKey){
76 if(checkCache(pKey)==false){
79 return whirlycache.remove(pKey);
82 //store object into the cache object with expire long value (in milliseconds)
83 public static void storeObjectIntoCache(String pKey,Object pObject,long pExpireDateLong){
84 if(checkCache(pKey)==false){
87 if(pExpireDateLong < 0){
88 //cache object with no expire date
89 whirlycache.store(pKey,pObject);
92 //cache object with expire date, this object will cleanup automatically after expire date
93 whirlycache.store(pKey,pObject,pExpireDateLong);