I've already replaced that implementation. I can paste here one from my 
local history. Beware, this might not be the right version and I don't 
know ehcache very well, I'm pretty sure there are ways to do this better.

Of course i've played with the cache configuration, this is probably not 
something that works best.

-Matej

public class TestFilePageStore implements IPageStore
{
        /** log. */
        protected static Log log = LogFactory.getLog(TestFilePageStore.class);

        private Cache cache;
        
        public TestFilePageStore()
        {
                CacheManager manager = CacheManager.create();
                String path = 
((WebApplication)Application.get()).getServletContext().getAttribute(
                                "javax.servlet.context.tempdir").toString();
                
                cache = new Cache("cache1", 50, true, true, 0, 0);
                manager.addCache(cache);
        }
        
        public void destroy()
        {
        }

        private static class SessionPageKey implements Serializable
        {
                private static final long serialVersionUID = 1L;
                
                private final String sessionId;
                private final int id;
                private final int versionNumber;
                private final int ajaxVersionNumber;
                private final String pageMap;

                SessionPageKey(String sessionId, Page page)
                {
                        this(sessionId, page.getNumericId(), 
page.getCurrentVersionNumber(), page
                                        .getAjaxVersionNumber(), 
page.getPageMap().getName());
                }

                SessionPageKey(String sessionId, int id, int versionNumber, int 
ajaxVersionNumber,
                                String pagemap)
                {
                        this.sessionId = sessionId;
                        this.id = id;
                        this.versionNumber = versionNumber;
                        this.ajaxVersionNumber = ajaxVersionNumber;
                        this.pageMap = pagemap;
                }

                /**
                 * @see java.lang.Object#hashCode()
                 */
                public int hashCode()
                {
                        return sessionId.hashCode() + id * 13 + versionNumber;
                }

                /**
                 * @see java.lang.Object#equals(java.lang.Object)
                 */
                public boolean equals(Object obj)
                {
                        if (obj instanceof SessionPageKey)
                        {
                                SessionPageKey key = (SessionPageKey)obj;
                                return id == key.id
                                                && versionNumber == 
key.versionNumber
                                                && ajaxVersionNumber == 
key.ajaxVersionNumber
                                                && ((pageMap != null && 
pageMap.equals(key.pageMap)) || (pageMap 
== null && key.pageMap == null))
                                                && 
sessionId.equals(key.sessionId);
                        }
                        return false;
                }

                /**
                 * @see java.lang.Object#toString()
                 */
                public String toString()
                {
                        return "SessionPageKey[" + sessionId + "," + id + "," + 
versionNumber 
+ ","
                                        + ajaxVersionNumber + ", " + pageMap + 
"]";
                }
        }

        
        public Page getPage(String sessionId, String pagemap, int id, int 
versionNumber, int ajaxVersionNumber)
        {
                SessionPageKey key = new SessionPageKey(sessionId, id, 
versionNumber, 
ajaxVersionNumber, pagemap);
                return (Page) cache.get(key).getValue();
                
        }

        public void pageAccessed(String sessionId, Page page)
        {
        }

        public void removePage(String sessionId, Page page)
        {
        }

        public void storePage(String sessionId, Page page)
        {
                SessionPageKey key = new SessionPageKey(sessionId, page);
                cache.put(new Element(key, page));
        }

        public void unbind(String sessionId)
        {
                List keys = cache.getKeys();
                for (Iterator i = keys.iterator(); i.hasNext(); ) {
                        SessionPageKey key = (SessionPageKey) i.next();
                        if (key.sessionId.equals(sessionId))
                                cache.remove(key);
                }
        }


Andrew Klochkov wrote:
> Johan Compagner wrote:
>> and i am completely not suprised that ehcache was not performing better.
>> How could it do that?? Where should the gain come from?
>> The current impl really grows directly with the hardware you have.
>> ehcache need to be tweaked exactly
>> what your system can handle. What do you say then? 200 page? 2000
>> pages? What does that cost?
> Although I don't know all details of wicket needs for caching yet but
> I'll try to explain my idea.
> 
> I think that storing every page on the disk is not good. With ehcache we
> can create a cache with limited in-memory size and unlimited on-disk
> size. Then we'll put every page in the cache, and when we'll access
> frequently used pages - they'll be got from memory, others will be read
> from the disk. That's where it can perform better - working with the
> file system only when it's really needed. And also there threading
> issues which are solved and tested in ehcache.
> 
> Matej, can you share you ehcache impl?
> 


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to