001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.query;
020
021import java.io.IOException;
022import java.util.Date;
023
024import lucee.runtime.PageContext;
025import lucee.runtime.db.SQL;
026import lucee.runtime.type.Query;
027
028/**
029 * interface for a query cache
030 */
031public interface QueryCache {
032
033    /**
034     * clear expired queries from cache
035     * @throws IOException 
036     */
037    public abstract void clearUnused(PageContext pc) throws IOException;
038
039    /**
040     * returns a Query from Query Cache or null if no match found
041     * @param sql
042     * @param datasource
043     * @param username
044     * @param password
045     * @param cacheAfter
046     * @return Query
047     */
048    public abstract Query getQuery(PageContext pc,SQL sql, String datasource, String username, String password, Date cacheAfter);
049    
050    
051    /**
052     * sets a Query to Cache
053     * @param sql
054     * @param datasource
055     * @param username
056     * @param password
057     * @param value
058     * @param cacheBefore
059     */
060    public abstract void set(PageContext pc,SQL sql, String datasource, String username,
061            String password, Object value, Date cacheBefore);
062
063    /**
064     * clear the cache
065     * @throws IOException 
066     */
067    public abstract void clear(PageContext pc);
068
069        /**
070         * clear the cache
071     * @param filter
072         */
073        public abstract void clear(PageContext pc, QueryCacheFilter filter);
074
075        /**
076         * removes query from cache
077         * @param sql
078         * @param datasource
079         * @param username
080         * @param password
081         * @throws IOException 
082         */
083        public abstract void remove(PageContext pc,SQL sql, String datasource,String username, String password);
084
085        public abstract Object get(PageContext pc,SQL sql, String datasource,String username, String password, Date cachedafter);
086
087        public abstract int size(PageContext pc);
088}