Examples of CachedObject


Examples of org.apache.turbine.services.cache.CachedObject

     * @throws Exception
     */   
    public void testObjectExpiration() throws Exception {
        String testString = new String( "This is a test");
        Object retrievedObject = null;
        CachedObject cacheObject = null;
       
//        getLogger().warn("This test will take a few mintes");
        System.out.println("This test will take a few mintes");
       
        GlobalCacheService globalCache = (GlobalCacheService)TurbineServices
        .getInstance()
        .getService( GlobalCacheService.SERVICE_NAME );
       
        // Create and add Object that expires in 1000 millis (1 second)
        cacheObject = new CachedObject(testString, 1000);
        assertNotNull( "Failed to create a cachable object", cacheObject);
        long addTime = System.currentTimeMillis();
        globalCache.addObject(cacheKey, cacheObject);
       
        // Try to get un-expired object
View Full Code Here

Examples of org.apache.turbine.services.cache.CachedObject

     */   

    public void testCacheFlush() throws Exception {
        String testString = new String( "This is a test");
        Object retrievedObject = null;
        CachedObject cacheObject = null;
       

        GlobalCacheService globalCache = (GlobalCacheService)TurbineServices
        .getInstance()
        .getService( GlobalCacheService.SERVICE_NAME );
       
        // Create and add Object that expires in 1 turbine Refresh + 1 millis
        cacheObject = new CachedObject(testString, (TURBINE_CACHE_REFRESH*5) + 1);
        assertNotNull( "Failed to create a cachable object", cacheObject);
        long addTime = System.currentTimeMillis();
        globalCache.addObject(cacheKey, cacheObject);

        // 1 Refresh
View Full Code Here

Examples of org.apache.turbine.services.cache.CachedObject

        .getService( GlobalCacheService.SERVICE_NAME );
        assertNotNull("Could not retrive cache service.", globalCache);
       
        // Create and add Object that expires in 1.5 turbine Refresh
        long expireTime = TURBINE_CACHE_REFRESH + TURBINE_CACHE_REFRESH/2;
        CachedObject cacheObject = new CachedObject("This is a test", expireTime);
        assertNotNull( "Failed to create a cachable object", cacheObject);

        globalCache.addObject(cacheKey, cacheObject);
        assertEquals("After adding 1 Object", 1, globalCache.getNumberOfObjects());
       
View Full Code Here

Examples of org.apache.turbine.services.cache.CachedObject

        if ( handle.length() == 0 ) {
            throw new RuntimeException("You must specify a handle for the item you want to cache.");
        }
       
        if ( item.isCacheable() ) {
            CachedObject cachedObject = null;
            Long expirationMillis = item.getExpirationMillis();
            if (expirationMillis != null) {
                if (System.currentTimeMillis() < expirationMillis.longValue()) {
                    cachedObject.setExpires(expirationMillis.longValue() - cachedObject.getCreated());
                }
            }
            if (item instanceof Refreshable) {
                RefreshableCachedObject rco = new RefreshableCachedObject( (Refreshable) item);
                if (item instanceof AbstractPortlet) {
                    AbstractPortlet portlet = (AbstractPortlet)item;
                    String tempString =  portlet.getPortletConfig().getInitParameter(JetspeedResources.TIME_TO_LIVE);
                    if (tempString != null) {
                        rco.setTTL(Integer.parseInt(tempString));
                        if (logger.isWarnEnabled())
                        {
                            logger.warn("PortletCache: portlet "
                                     + item.getHandle()
                                     + " overrides default time to live with "
                                     + tempString);
                        }
                    } else {
                        rco.setTTL(DefaultTimeToLiveMillis);
                    }
                } else {
                    rco.setTTL(DefaultTimeToLiveMillis);
                }
                cachedObject = rco;
               
            } else {
                cachedObject = new CachedObject(item);
            }
            item.setCachedObject(cachedObject);

            // Add object to cache
            GlobalCache.addObject( handle , cachedObject);
View Full Code Here

Examples of org.apache.turbine.services.cache.CachedObject

     * @see PortletCacheService#removeCacheable
     * @param handle the identifier of the object we wish to retrieve
     */
    public void removeCacheable( String handle ) {
       
        CachedObject obj = null;
       
        try {
            obj = GlobalCache.getObject( handle );
        } catch ( ObjectExpiredException e) {
            // nothing to do if already expired
        }
       
        if ( obj != null ) {
            obj.setStale(true);
        }
    }
View Full Code Here

Examples of org.apache.turbine.services.cache.CachedObject

     * @param handle the identifier of the object we wish to retrieve
     * @return the cacehd object or null if not found
     */
    public Cacheable getCacheable( String handle ) {
       
        CachedObject obj = null;
       
        try {
            obj = GlobalCache.getObject( handle );
        } catch (ObjectExpiredException e) {
            logger.info( "cache miss, object expired: " + handle );
        }
       
        if ( obj == null ) {
            //Log.info( "cache miss: " + handle );
            return null;
        } /*else {
            Log.info( "cache hit: " + handle );
            } */
       
        return (Cacheable)obj.getContents();
       
    }
View Full Code Here

Examples of org.apache.turbine.services.cache.CachedObject

     * @throws Exception
     */
    public void testSimpleAddGetCacheObject() throws Exception {
        String testString = new String( "This is a test");
        Object retrievedObject = null;
        CachedObject cacheObject1 = null;
       
        GlobalCacheService globalCache = (GlobalCacheService)TurbineServices
        .getInstance()
        .getService( GlobalCacheService.SERVICE_NAME );
       
        // Create object
        cacheObject1 = new CachedObject(testString);
        assertNotNull( "Failed to create a cachable object 1", cacheObject1);
       
        // Add object to cache
        globalCache.addObject(cacheKey, cacheObject1);
       
View Full Code Here

Examples of org.apache.turbine.services.cache.CachedObject

     * @throws Exception
     */
    public void test2ObjectAddGetCachedObject() throws Exception {
        String testString = new String( "This is a test");
        Object retrievedObject = null;
        CachedObject cacheObject1 = null;
        CachedObject cacheObject2 = null;
       
        GlobalCacheService globalCache = (GlobalCacheService)TurbineServices
        .getInstance()
        .getService( GlobalCacheService.SERVICE_NAME );
       
        // Create and add Object #1
        cacheObject1 = new CachedObject(testString);
        assertNotNull( "Failed to create a cachable object 1", cacheObject1);
        globalCache.addObject(cacheKey, cacheObject1);
        retrievedObject = globalCache.getObject(cacheKey);
        assertNotNull( "Did not retrieved a cached object 1", retrievedObject);
        assertEquals( "Did not retrieved correct cached object", cacheObject1, retrievedObject);
       
        // Create and add Object #2
        cacheObject2 = new CachedObject(testString);
        assertNotNull( "Failed to create a cachable object 2", cacheObject2);
        globalCache.addObject(cacheKey_2, cacheObject2);
        retrievedObject = globalCache.getObject(cacheKey_2);
        assertNotNull( "Did not retrieved a cached object 2", retrievedObject);
        assertEquals( "Did not retrieved correct cached object 2", cacheObject2, retrievedObject);
View Full Code Here

Examples of org.hsqldb.persist.CachedObject

            database.persistentStoreCollection.getStore(this);
        int[] roots = new int[indexList.length * 2 + 1];
        int   i     = 0;

        for (int index = 0; index < indexList.length; index++) {
            CachedObject accessor = store.getAccessor(indexList[index]);

            roots[i++] = accessor == null ? -1
                                          : accessor.getPos();
        }

        for (int index = 0; index < indexList.length; index++) {
            roots[i++] = indexList[index].sizeUnique(store);
        }
View Full Code Here

Examples of org.hsqldb.persist.CachedObject

            try {
                if (Table.this.isText) {
                    return new CachedDataRow(Table.this, in);
                }

                CachedObject row = new CachedRow(Table.this, in);

                return row;
            } catch (HsqlException e) {
                return null;
            } catch (IOException e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.