Package railo.commons.io.cache

Examples of railo.commons.io.cache.Cache


  }

  @Override
  public void clearUnused(PageContext pc) throws IOException {
   
    Cache c = getCache(pc);
    List<CacheEntry> entries = c.entries();
    if(entries.size()<100) return;
   
    Iterator<CacheEntry> it = entries.iterator();
    while(it.hasNext()){
      it.next(); // touch them to makes sure the cache remove them, not really good, cache must do this by itself
View Full Code Here


    long timeSpan = ((cacheBefore.getTime()-System.currentTimeMillis())+1);
    getCache(pc).put(key(sql, datasource, username, password), new QueryCacheEntry(cacheBefore,value), Long.valueOf(timeSpan), Long.valueOf(timeSpan));
  }

  private Cache getCache(PageContext pc) {
    Cache c = Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_QUERY,DEFAULT_CACHE)
    return c;
  }
View Full Code Here

      _clear(pc,filter);
    } catch (IOException e) {}
    }

  private void _clear(PageContext pc,QueryCacheFilter filter) throws IOException {
    Cache c = getCache(pc);
    Iterator it = c.entries().iterator();
      String key;
      CacheEntry entry;
      QueryCacheEntry ce;
      Query q;
      while(it.hasNext()){
      entry=(CacheEntry) it.next();
      if(!(entry.getValue() instanceof QueryCacheEntry)) continue;
      ce=(QueryCacheEntry) entry.getValue();
      if(!(ce.getValue() instanceof Query)) continue;
      q=(Query) ce.getValue();
      key=entry.getKey();
        if(filter.accept(q.getSql().toString())){
        c.remove(key);
        }
      }
  }
View Full Code Here

    setTimeSpan(pc);
    super.touchBeforeRequest(pc);
  }
 
  protected static Struct _loadData(PageContext pc, String cacheName, String appName, String strType, Log log) throws PageException  {
    Cache cache = getCache(pc.getConfig(),cacheName);
    String key=getKey(pc.getCFID(),appName,strType);
   
    Struct s = (Struct) cache.getValue(key,null);
   
    if(s!=null)
      ScopeContext.info(log,"load existing data from  cache ["+cacheName+"] to create "+strType+" scope for "+pc.getApplicationContext().getName()+"/"+pc.getCFID());
    else
      ScopeContext.info(log,"create new "+strType+" scope for "+pc.getApplicationContext().getName()+"/"+pc.getCFID()+" in cache ["+cacheName+"]");
View Full Code Here

    return s;
  }

  public void store(Config config) {
    try {
      Cache cache = getCache(config, cacheName);
      /*if(cache instanceof CacheEvent) {
        CacheEvent ce=(CacheEvent) cache;
        ce.register(new SessionEndCacheEvent());
      }*/
      String key=getKey(cfid, appName, getTypeAsString());
      cache.put(key, sct,new Long(getTimeSpan()), null);
    }
    catch (Exception pe) {}
  }
View Full Code Here

    catch (Exception pe) {}
  }
 
  public void unstore(Config config) {
    try {
      Cache cache = getCache(config, cacheName);
      String key=getKey(cfid, appName, getTypeAsString());
      cache.remove(key);
    }
    catch (Exception pe) {}
  }
View Full Code Here

    }
   
  }

  private void clean(CacheConnection cc, ConfigWebImpl config) throws IOException {
    Cache cache = cc.getInstance(config);
    int len=filter.length(),index;
    List<CacheEntry> entries = cache.entries(filter);
    CacheEntry ce;
    long expires;
   
    String key,appname,cfid;
    if(entries.size()>0){
      Iterator<CacheEntry> it = entries.iterator();
      while(it.hasNext()){
        ce=it.next();
        expires=ce.lastModified().getTime()+ce.idleTimeSpan()-StorageScopeCache.SAVE_EXPIRES_OFFSET;
        if(expires<=System.currentTimeMillis()) {
          key=ce.getKey().substring(len);
          index=key.indexOf(':');
          cfid=key.substring(0,index);
          appname=key.substring(index+1);
         
          if(listener!=null)listener.doEnd(engine, this,appname, cfid);
          info("remove "+strType+"/"+appname+"/"+cfid+" from cache "+cc.getName());
          engine.remove(type,appname,cfid);
          cache.remove(ce.getKey());
        }
      }
    }
   
    //engine.remove(type,appName,cfid);
View Full Code Here

    private Object _callCachedWithin(PageContext pc,Collection.Key calledName, Object[] args, Struct values,boolean doIncludePath) throws PageException {
      PageContextImpl pci=(PageContextImpl) pc;
      String id = UDFUtil.callerHash(this,args,values);
     
    Cache cache = Util.getDefault(pc,ConfigImpl.CACHE_DEFAULT_FUNCTION,DEFAULT_CACHE)
    Object o =  cache.getValue(id,null);
   
    // get from cache
    if(o instanceof UDFCacheEntry ) {
      UDFCacheEntry entry = (UDFCacheEntry)o;
      //if(entry.creationdate+properties.cachedWithin>=System.currentTimeMillis()) {
        try {
          pc.write(entry.output);
        } catch (IOException e) {
          throw Caster.toPageException(e);
        }
        return entry.returnValue;
      //}
     
      //cache.remove(id);
    }
     
    // execute the function
    BodyContent bc =  pci.pushBody();
     
      try {
        Object rtn = _call(pci,calledName, args, values, doIncludePath);
        String out = bc.getString();
        cache.put(id, new UDFCacheEntry(out, rtn),properties.cachedWithin,properties.cachedWithin);
        return rtn;
    }
        finally {
          BodyContentUtil.flushAndPop(pc,bc);
        }
View Full Code Here

    return call(pc, filter, null);
  }
 
  public static Array call(PageContext pc, String filter, String cacheName) throws PageException {
    try {
      Cache cache = Util.getCache(pc,cacheName,ConfigImpl.CACHE_DEFAULT_OBJECT);
     
      List<String> keys = isFilter(filter)?cache.keys(new WildCardFilter(filter,true)):cache.keys();
      Iterator<String> it = keys.iterator();
      Array arr = new ArrayImpl();
      while(it.hasNext()){
        arr.append(it.next());
      }
View Full Code Here

    return call(pc, filter,null);
  }
 
  public static Struct call(PageContext pc,String filter, String cacheName) throws PageException {
    try {
      Cache cache = Util.getCache(pc,cacheName,ConfigImpl.CACHE_DEFAULT_OBJECT);
      List<CacheEntry> entries = CacheGetAllIds.isFilter(filter)?cache.entries(new WildCardFilter(filter,true)):cache.entries();
      Iterator<CacheEntry> it=entries.iterator();
      Struct sct = new StructImpl();
      CacheEntry entry;
      while(it.hasNext()){
        entry= it.next();
View Full Code Here

TOP

Related Classes of railo.commons.io.cache.Cache

Copyright © 2018 www.massapicom. 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.