001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.velocity;
016    
017    import com.liferay.portal.kernel.cache.MultiVMPoolUtil;
018    import com.liferay.portal.kernel.cache.PortalCache;
019    
020    import org.apache.velocity.runtime.resource.Resource;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     */
025    public class LiferayResourceCacheUtil {
026    
027            public static final String CACHE_NAME =
028                    LiferayResourceCacheUtil.class.getName();
029    
030            public static void clear() {
031                    _portalCache.removeAll();
032            }
033    
034            public static Resource get(String key) {
035                    Object resource = _portalCache.get(key);
036    
037                    if ((resource != null) && (resource instanceof Resource)) {
038                            return (Resource)resource;
039                    }
040    
041                    return null;
042            }
043    
044            public static void put(String key, Resource resource) {
045                    _portalCache.put(key, resource);
046            }
047    
048            public static void remove(String key) {
049                    _portalCache.remove(key);
050            }
051    
052            private static PortalCache _portalCache = MultiVMPoolUtil.getCache(
053                    CACHE_NAME);
054    
055    }