001 /* 002 Copyright (C) 2002 Laurent Martelli <laurent@aopsys.com> 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public License 015 along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 017 018 package org.objectweb.jac.aspects.cache; 019 020 import java.util.Iterator; 021 import org.apache.log4j.Logger; 022 import org.objectweb.jac.core.AspectComponent; 023 import org.objectweb.jac.core.rtti.AbstractMethodItem; 024 025 /** 026 * This aspect handle caching of method results. 027 */ 028 029 public class CacheAC extends AspectComponent implements CacheConf { 030 static final Logger logger = Logger.getLogger("cache"); 031 032 public static final String IGNORED_PARAMETERS = "CacheAC.IGNORED_PARAMETERS"; 033 034 /** 035 * Cache a method result. 036 * 037 * @param classExpr the classes 038 * @param methodExpr the methods cached 039 */ 040 public void cache(String classExpr, String methodExpr) 041 { 042 logger.info("cache "+classExpr+"."+methodExpr); 043 044 pointcut("ALL",classExpr,methodExpr, 045 "org.objectweb.jac.aspects.cache.CacheWrapper", 046 null,NOT_SHARED); 047 } 048 049 public void cacheWithTimeStamps( 050 String classExpr, String methodExpr, 051 String stampsName) 052 { 053 logger.info("cache "+classExpr+"."+methodExpr); 054 055 pointcut( 056 "ALL", classExpr, methodExpr, 057 "org.objectweb.jac.aspects.cache.CacheWrapper", 058 new Object[] {stampsName}, 059 null, 060 NOT_SHARED); 061 } 062 063 public void setIgnoredParameters(AbstractMethodItem method, 064 int[] ignored) 065 { 066 method.setAttribute(IGNORED_PARAMETERS,ignored); 067 } 068 069 public void invalidateCache() { 070 Iterator i = wrappers.iterator(); 071 while(i.hasNext()) { 072 CacheWrapper wrapper = (CacheWrapper)i.next(); 073 wrapper.invalidate(); 074 } 075 } 076 }