001/*******************************************************************************
002The MIT License (MIT)
003
004Copyright (c) 2024 KILLCODING.COM
005
006Permission is hereby granted, free of charge, to any person obtaining a copy
007of this software and associated documentation files (the "Software"), to deal
008in the Software without restriction, including without limitation the rights
009to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
010copies of the Software, and to permit persons to whom the Software is
011furnished to do so, subject to the following conditions:
012
013The above copyright notice and this permission notice shall be included in
014all copies or substantial portions of the Software.
015
016THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
017IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
018FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
019AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
020LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
021OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
022THE SOFTWARE.
023*****************************************************************************/
024package com.killcoding.cache;
025
026import com.killcoding.log.Logger;
027import com.killcoding.log.LoggerFactory;
028
029import java.util.List;
030import com.killcoding.cache.AbsCacheApi;
031import com.killcoding.cache.MemoryCache;
032
033/**
034 * This class is a permanent cache storage that requires manual deletion of the cache
035 * */
036public final class StoredCache {
037
038        private static AbsCacheApi api = new MemoryCache(true);
039        private static final Logger log = LoggerFactory.getLogger(StoredCache.class);
040        
041        public synchronized static void setApi(AbsCacheApi _api){
042            api = _api;
043        }
044
045        public synchronized static void set(String name,Object value){
046                log.debug("Set Cache: {}",name);
047                api.set(name, value, Integer.MAX_VALUE);                
048        }
049        
050        public synchronized static Object get(String name){
051                log.debug("Get Cache: {}",name);
052                return api.get(name);
053        }
054        
055        public synchronized static boolean included(String name){
056                log.debug("Included Cache: {}",name);
057                boolean b = api.included(name);
058                log.debug("Included: {}",b);
059                return b;
060        }
061        
062        public synchronized static void remove(String name){
063                log.debug("Remove Cache: {}",name);
064                api.remove(name);
065        }
066        
067        public synchronized static void removeAll(){
068                log.debug("Remove All Cache");
069                api.removeAll();
070        }
071        
072        public synchronized static List<String> getNames(){
073                return api.getNames();
074        }       
075
076        public synchronized static void shutdown(){
077                api.shutdown();
078        }       
079        
080}