From: Egbert T. <e.t...@st...> - 2006-12-29 17:58:06
|
Yo, I totally agree that a <mak:cache> or something would be awesome. = However, especially because the functionality of <c:set> and stuff reall= y = goes, as far as I know, into tomcat-specific internals, I think this wou= ld = be a very complicated task. Plus, I personally understand very little = about how tomcat or jsp in general works from the inside, and personally= = would prefer finishing four reasonably large ITC tasks in the time that = it = would take me to turn it into a taglib thingy instead.. So, for me, this= = is a rather "sufficient" solution for now. Actually, I did consider making it an <@include>able thing, but Rudi = convinced me not to because it hides some functionality that might well = = need to be page-specific. (wouldn't work with <jsp:include> btw because = of = the <c:set> thingy). I love your "custom key" idea, by the way, and will add it soon. -egbert On Mon, 25 Dec 2006 02:36:28 +0100, Stefan Baebler <st...@ba...> = = wrote: > Nice! > > However, a class that needs to be called before and after some content= = > just begs to be transformed to a taglib, so that somewhat long code: > ------- > <%! static org.eu.best.util.PageCache cache =3D new = > org.eu.best.util.PageCache(); %> > > <% cache.begin(request, pageContext); // sets JSTL attribute = > 'cachePageContent' %> > > <!-- // is update needed? --> > <c:if test=3D"${param.forceUpdate =3D=3D 'yes' || empty cachePageConte= nt}"> > <!--computed.--> > <c:set var=3D"cachePageContent"> > ...content... > </c:set> > <% cache.end(request, pageContext,1000*60*60*6); %> > </c:if> <%-- end:update the numbers --%> > > ${cachePageContent} > ------- > can be shortened to something like: > ------- > <%@ taglib uri=3D"http://www.makumba.org/presentation" prefix=3D"mak" = %> > > <mak:cache > timeout=3D"<%=3D1000*60*60*6 %>" > forceUpdate=3D"${param.forceUpdate =3D=3D 'yes'}" > cachedPrefix=3D"<!--from cache, computed at %timestamp% -->" > evaluatedPrefix=3D"<!--computed-->" > > > ...content... > </mak:cache> > ------- > it doesn't necesarily need to be in mak taglib, as it is an isolated = > functionality, but for ease of use it might as well go in there. > > Once you have the code centralized (pages remaining relatively code = > free) you can centrally manage (config file) where cache is stored (di= sk = > instead of memory), default cache timeout... > > a more important thing... not only query string defines the content, = > there might be also some other attributes (session, page....) or even = = > current date, so you might want to introduce a "key" parameter, comput= ed = > at runtime. > key=3D"<%=3Drequest.getQueryString()%>" (default, as it is now) > key=3D"<%=3Dnew java.util.Date("yyyy-MM-dd")%>" (eg for caching bi= rthday = > lists) > key=3D"<%=3Drequest.getQueryString()+session.getAttribute("user")%= >" > ... > > being such a general problem such taglib might already exist. See > http://www.google.com/search?q=3Dcache+taglib for code or ideas > > greets, > Stefan /fighting jetlag > > > Joao Oliveira wrote: >> hey guys, >> I just wanted to tell you that this was my lucky day, I was really = = >> really happy when Egbert came to me in ICQ and asked showed me this = >> class. >> Suddenly I remember this old task, that risto has been pushing me f= or = >> long :( (http://private.best.eu.org/tasks/task.jsp?task=3Dbz91v4y), a= nd = >> immediately I tried to test this class. >> I might say that code is *super hyper* shorter now, so clean that it= = >> really made me happy :) >> The examples speak for itself, go and check: >> http://tequila.best.eu.org/joao-k/johnny/applicationStatistics.jspx >> http://tequila.best.eu.org/joao-k/johnny/applicationStatistics.jspx >> I think that soon this can hit production if no1 else has anything = = >> against it. >> cheers and a merry christmas to all the nerds out there :) >> Egbert Teeselink wrote: >>> #mak-user in cc. >>> >>> hi ITD! >>> >>> I made a class for caching pages. The idea of it that pages that don= 't = >>> depend on which user is logged in, on the weather, or on the exact = >>> time might not need to be recomputed every time it is accessed. If t= he = >>> exact same information is sent to everybody requesting a page, why n= ot = >>> save the page itself instead of computing it with lots of mak:values= = >>> and db accesses every time? So, in short, this is a method of = >>> optimisation. >>> >>> The class saves a different page for every different query string th= at = >>> a page gets passed. This allows you to put caches on pages even if = >>> they might display different information in different cases. >>> >>> I tried it make it as easy to use for JSP authors as possible, and = >>> made some documentation inside the class file. If you're interested,= = >>> please check out = >>> http://tequila.best.eu.org/egbert-k/classes/org.eu.best.util.PageCac= he = >>> and give me some comments or whatever. >>> >>> I started making it (jsp-based at first) for pages that allow local = = >>> webmasters to import information like the BAS event list into their = = >>> websites automatically, and figured that that could easily lead to a= = >>> very heavy server load. But then, after some feedback from Rudi, we = = >>> figured it might be more widely applicable. So here :-) >>> >>> Joao already expressed an interest in it for a task of his, so maybe= = >>> it's a good idea to already put it into production quite soon, even = if = >>> I haven't finished the local webmaster tools thingy yet. So, feedbac= k = >>> please :) >>> >>> One thing that I see that could maybe become a problem is that the = >>> cached pages are saved inside the server's memory. The event list pa= ge = >>> is easily 30kb, and for multiple different query strings that page = >>> would be saved multiple times. If we start doing this thing a lot, w= e = >>> might get into quite some megabytes. Does some server guru know = >>> whether this would make a problem? Or is it swapped automatically? O= r = >>> something? >>> >>> -egbert >>> >>> ps. a page that works with it is = >>> http://tequila.best.eu.org/egbert-k/www/localWeb/eventList.jsp - try= = >>> reloading the context, and you'll find a <!--computed.--> comment on= = >>> top of that page. Reload the page itself only, and the = >>> <!--computed.--> comment is gone. Note that the page itself is an = >>> outdated and work-in-progress thing, please don't look at the conten= t = >>> of it :-) >>> >>> >> > |