Package com.opensymphony.oscache.general

Examples of com.opensymphony.oscache.general.GeneralCacheAdministrator


    }
   
    public void testGroupNames() {

        Properties props = new Properties();
        OSQueryCache c1 = new OSQueryCache(new GeneralCacheAdministrator(), props);
        assertTrue(c1.getGroupNames().isEmpty());

        props.put(OSQueryCache.GROUP_PREFIX + "ABC" + OSQueryCache.REFRESH_SUFFIX, "25");
        props.put(
                OSQueryCache.GROUP_PREFIX + "XYZ" + OSQueryCache.CRON_SUFFIX,
                "24 * * * * *");

        OSQueryCache c2 = new OSQueryCache(new GeneralCacheAdministrator(), props);

        assertEquals(2, c2.getGroupNames().size());

        assertTrue(c2.getGroupNames().contains("ABC"));
        assertTrue(c2.getGroupNames().contains("XYZ"));
View Full Code Here


    synchronized(OSCacheProvider.class)
    {
      if (dataCache == null)
      {
        // todo: Give properties ...
        dataCache = new GeneralCacheAdministrator();
      }
      return new OSResourceDataCache(dataCache);
    }
  }
View Full Code Here

    synchronized(OSCacheProvider.class)
    {
      if (factoryCache == null)
      {
        // todo: Give properties ...
        factoryCache = new GeneralCacheAdministrator();
      }
      return new OSResourceFactoryCache(factoryCache);
    }
  }
View Full Code Here

    synchronized(OSCacheProvider.class)
    {
      if (dataCache == null)
      {
        // todo: Give properties ...
        dataCache = new GeneralCacheAdministrator();
      }
      return new OSResourceDataCache(dataCache);
    }
  }
View Full Code Here

    synchronized(OSCacheProvider.class)
    {
      if (factoryCache == null)
      {
        // todo: Give properties ...
        factoryCache = new GeneralCacheAdministrator();
      }
      return new OSResourceFactoryCache(factoryCache);
    }
  }
View Full Code Here

      Properties cacheProperties = cacheConfigurationloader.loadProperties("oscache.properties");
      cacheProperties.putAll(cacheConfigurationloader.loadProperties("/oscache.properties"));
      cacheProperties.putAll(env);
     
      log.info("Creating OSCache cache instance using parameters: " + cacheProperties);     
      GeneralCacheAdministrator cacheAdministrator = new GeneralCacheAdministrator(cacheProperties);
    return new OSCacheCache(cacheAdministrator.getCache(), cacheLoader);
  }
View Full Code Here

    if(useMemoryCache)
    {
        if(!caches.containsKey(cacheName))
        {
          GeneralCacheAdministrator cacheAdministrator = null;
          Map cacheSettings = (Map)getCachedObject("serverNodePropertiesCacheSettings", "cacheSettings");
          if(cacheSettings == null)
          {
            cacheSettings = CmsPropertyHandler.getCacheSettings();
            cacheObject("serverNodePropertiesCacheSettings", "cacheSettings", cacheSettings);
          }
         
          String cacheCapacity = (String)cacheSettings.get("CACHE_CAPACITY_" + cacheName);
          if(cacheCapacity == null || !cacheCapacity.equals(""))
            cacheCapacity = "15000";
                   
          if(cacheName != null && cacheName.startsWith("contentAttributeCache"))
            cacheCapacity = "50000";
          if(cacheName != null && cacheName.startsWith("metaInfoContentAttributeCache"))
            cacheCapacity = "40000";
          //else if(cacheName != null && cacheName.startsWith("contentAttributeCache"))
          //  cacheCapacity = "1000";
          String pageCacheSize = "100";
          String pageCacheExtraSize = "300";
          if(CmsPropertyHandler.getOperatingMode().equals("3"))
          {
            pageCacheSize = "10000";
            pageCacheExtraSize = "30000";
          }
         
          if(cacheName != null && cacheName.startsWith("pageCache"))
            cacheCapacity = pageCacheSize;
          if(cacheName != null && cacheName.startsWith("pageCacheExtra"))
            cacheCapacity = pageCacheExtraSize;
        if(cacheName != null && cacheName.equalsIgnoreCase("encodedStringsCache"))
          cacheCapacity = "2000";
        if(cacheName != null && cacheName.equalsIgnoreCase("assetUrlCacheWithGroups"))
          cacheCapacity = "10000";
        if(cacheName != null && cacheName.equalsIgnoreCase("importTagResultCache"))
          cacheCapacity = "500";
        if(cacheName != null && cacheName.equalsIgnoreCase("componentPropertyCache"))
          cacheCapacity = "10000";
        if(cacheName != null && cacheName.equalsIgnoreCase("componentPropertyVersionIdCache"))
          cacheCapacity = "10000";
        if(cacheName != null && cacheName.equalsIgnoreCase("componentPropertyCacheRepoGroups"))
          cacheCapacity = "5000";
        if(cacheName != null && cacheName.equalsIgnoreCase("componentPropertyVersionIdCacheRepoGroups"))
          cacheCapacity = "5000";
        if(cacheName != null && cacheName.equalsIgnoreCase("componentEditorCache"))
            cacheCapacity = "3000";
        if(cacheName != null && cacheName.equalsIgnoreCase("componentEditorVersionIdCache"))
            cacheCapacity = "3000";
        if(cacheName != null && cacheName.equalsIgnoreCase("contentVersionIdCache"))
            cacheCapacity = "30000";
        if(cacheName != null && cacheName.equalsIgnoreCase("contentVersionCache"))
            cacheCapacity = "30000";
        if(cacheName != null && cacheName.equalsIgnoreCase("pageComponentsCache"))
            cacheCapacity = "10000";
        if(cacheName != null && cacheName.equalsIgnoreCase("boundContentCache"))
            cacheCapacity = "5000";
        if(cacheName != null && cacheName.equalsIgnoreCase("childSiteNodesCache"))
            cacheCapacity = "20000";
        if(cacheName != null && cacheName.equalsIgnoreCase("childPagesCache"))
            cacheCapacity = "20000";
        if(cacheName != null && cacheName.equalsIgnoreCase("siteNodeCache"))
            cacheCapacity = "20000";
        if(cacheName != null && cacheName.equalsIgnoreCase("contentCache"))
            cacheCapacity = "20000";
        if(cacheName != null && cacheName.equalsIgnoreCase("latestSiteNodeVersionCache"))
            cacheCapacity = "20000";
        if(cacheName != null && cacheName.equalsIgnoreCase("pageDeliveryMetaDataCache"))
            cacheCapacity = "50000";
       
        /*
        if(cacheCapacity.length() > 4)
          cacheCapacity = "10000";
        */
        /*
        if(cacheName != null && (cacheName.equalsIgnoreCase("contentAttributeCache_Title") ||
                     cacheName.equalsIgnoreCase("contentAttributeCache_NavigationTitle") ||
                     cacheName.equalsIgnoreCase("contentAttributeCache_hideInNavigation") ||
                     cacheName.equalsIgnoreCase("contentAttributeCache_SortOrder")))
        {
          cacheCapacity = "100000";
        }
        */
       
        if(cacheCapacity != null && !cacheCapacity.equals(""))
          {
          Properties p = new Properties();
          String cacheAlgorithm = (String)cacheSettings.get("CACHE_ALGORITHM_" + cacheName);
          if(cacheAlgorithm == null || cacheAlgorithm.equals(""))
            p.setProperty(AbstractCacheAdministrator.CACHE_ALGORITHM_KEY, "com.opensymphony.oscache.base.algorithm.ImprovedLRUCache");
          else
            p.setProperty(AbstractCacheAdministrator.CACHE_ALGORITHM_KEY, cacheAlgorithm);
         
          //p.setProperty(AbstractCacheAdministrator.CACHE_ALGORITHM_KEY, "com.opensymphony.oscache.base.algorithm.LRUCache");
          p.setProperty(AbstractCacheAdministrator.CACHE_CAPACITY_KEY, cacheCapacity);
          cacheAdministrator = new GeneralCacheAdministrator(p);
        }
        else
        {
          cacheAdministrator = new GeneralCacheAdministrator();
        }
           
            CacheEntryEventListenerImpl cacheEntryEventListener = new ExtendedCacheEntryEventListenerImpl();
        CacheMapAccessEventListenerImpl cacheMapAccessEventListener = new CacheMapAccessEventListenerImpl();
           
        cacheAdministrator.getCache().addCacheEventListener(cacheEntryEventListener, CacheEntryEventListener.class);
        cacheAdministrator.getCache().addCacheEventListener(cacheMapAccessEventListener, CacheMapAccessEventListener.class);
        caches.put(cacheName, cacheAdministrator);
        //locksCache.put(cacheName, new ReentrantReadWriteLock());
        }
       
      GeneralCacheAdministrator cacheAdministrator = (GeneralCacheAdministrator)caches.get(cacheName);
     
      //if(cacheName.startsWith("contentAttribute")/* || cacheName.startsWith("contentVersionIdCache")*/)
      //  useGroups = false;

      //boolean containsSelectiveCacheUpdateNonApplicable = false;
      if(groups != null)
      {
        List<String> groupCandidateListStandard = new ArrayList<String>();
        List<String> groupCandidateListSpecial = new ArrayList<String>();
        for(int i=0; i<groups.length; i++)
        {
          if(groups[i].startsWith("content") || groups[i].startsWith("siteNode"))
            groupCandidateListStandard.add(groups[i]);
          else
            groupCandidateListSpecial.add(groups[i]);
        }
       
        if(!groupCandidateListSpecial.contains("selectiveCacheUpdateNonApplicable"))
        {
          groupCandidateListSpecial.addAll(groupCandidateListStandard);
        }
        String[] newGroups = new String[groupCandidateListSpecial.size()];
        groups = groupCandidateListSpecial.toArray(newGroups);
      }
     
      if(logger.isInfoEnabled() && cacheName.equalsIgnoreCase("pageCacheExtra"))
      {
        logger.info("real groups: " + (groups == null ? "null" : groups.length));
        if(groups != null)
        {
          for(String group : groups)
            logger.info(group + ",");
        }
      }
     
      //Kanske tillbaka om minnet sticker
      if(cacheName.equals("componentPropertyCache") || cacheName.equals("componentPropertyVersionIdCache"))
      {       
        //logger.error("Skipping useGroups on " + cacheName + ". Groups was:" + groups.length + " for " + key);
        useGroups = false;
      }
      /*
      if(cacheName.equals("componentPropertyCache") || cacheName.equals("componentPropertyVersionIdCache"))
      {       
        //logger.error("Skipping useGroups on " + cacheName + ". Groups was:" + groups.length + " for " + key);
        useGroups = false;
      }
      */
           
      /*
      if(cacheName.startsWith("pageCache"))
      {
        //logger.error("Skipping useGroups on pageCache. Groups was:" + groups.length + " for " + key);
        useGroups = false;       
      }
      */
           
      //TODO
      if(CmsPropertyHandler.getUseSynchronizationOnCaches())
      {
        synchronized(cacheAdministrator) //Back
          {
          try
          {
            if(useGroups)
            {
              if(CmsPropertyHandler.getUseHashCodeInCaches())
                cacheAdministrator.putInCache("" + key.toString().hashCode(), value, groups);
              else
                cacheAdministrator.putInCache(key.toString(), value, groups);
            }
            else
            {
              if(CmsPropertyHandler.getUseHashCodeInCaches())
                cacheAdministrator.putInCache("" + key.toString().hashCode(), value);
              else
                  cacheAdministrator.putInCache(key.toString(), value);
            }
          }
          catch (Exception e)
          {
            logger.warn("Error putting in cache:" + e.getMessage());
          }
                //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Putting object in " + cacheName, t.getElapsedTime());
        }
      }
      else
      {
        try
        {
          if(useGroups)
          {
            if(CmsPropertyHandler.getUseHashCodeInCaches())
              cacheAdministrator.putInCache("" + key.toString().hashCode(), value, groups);
            else
              cacheAdministrator.putInCache(key.toString(), value, groups);
          }
          else
          {
            if(CmsPropertyHandler.getUseHashCodeInCaches())
              cacheAdministrator.putInCache("" + key.toString().hashCode(), value);
            else
                cacheAdministrator.putInCache(key.toString(), value);
          }
        }
        catch (Exception e)
        {
          logger.warn("Error putting in cache:" + e.getMessage(), e);
View Full Code Here

      logger.info("persistentCachesBetweenRestarts: "+ persistentCachesBetweenRestarts);
    }

      if(!caches.containsKey(cacheName))
      {
        GeneralCacheAdministrator cacheAdministrator = null;
     
      Properties p = new Properties();
     
      p.setProperty(AbstractCacheAdministrator.CACHE_MEMORY_KEY, Boolean.toString(useMemoryCache));
      p.setProperty(AbstractCacheAdministrator.CACHE_DISK_UNLIMITED_KEY, Boolean.toString(unlimitedDiskCache));
      p.setProperty(AbstractCacheAdministrator.CACHE_CAPACITY_KEY, "" + memoryCacheSize);
      p.setProperty(AbstractCacheAdministrator.CACHE_PERSISTENCE_OVERFLOW_KEY, Boolean.toString(useFileCacheFallback));
     
      p.setProperty(AbstractCacheAdministrator.CACHE_ALGORITHM_KEY, "com.opensymphony.oscache.base.algorithm.ImprovedLRUCache");
      p.setProperty("cache.persistence.class", "com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener");
      p.setProperty("cache.path", CmsPropertyHandler.getDigitalAssetPath() + File.separator + (persistentCachesBetweenRestarts ? "persistentCaches" : "caches") + File.separator + cacheName);
     
      cacheAdministrator = new GeneralCacheAdministrator(p);
     
      //Adding one entry just to get the disk cache active
      if(useFileCacheFallback && memoryCacheSize == 1)
         cacheAdministrator.putInCache("dummy", "value");
     
          //CacheEntryEventListenerImpl cacheEntryEventListener = new ExtendedCacheEntryEventListenerImpl();
      //CacheMapAccessEventListenerImpl cacheMapAccessEventListener = new CacheMapAccessEventListenerImpl();
         
      //cacheAdministrator.getCache().addCacheEventListener(cacheEntryEventListener, CacheEntryEventListener.class);
      //cacheAdministrator.getCache().addCacheEventListener(cacheMapAccessEventListener, CacheMapAccessEventListener.class);
          caches.put(cacheName, cacheAdministrator);
          //locksCache.put(cacheName, new ReentrantReadWriteLock());
          //eventListeners.put(cacheName + "_cacheEntryEventListener", cacheEntryEventListener);
          //eventListeners.put(cacheName + "_cacheMapAccessEventListener", cacheMapAccessEventListener);
      }
     
    GeneralCacheAdministrator cacheAdministrator = (GeneralCacheAdministrator)caches.get(cacheName);
     
    if(groups != null)
    {
      List<String> groupCandidateListStandard = new ArrayList<String>();
      List<String> groupCandidateListSpecial = new ArrayList<String>();
      for(int i=0; i<groups.length; i++)
      {
        if(groups[i].startsWith("content") || groups[i].startsWith("siteNode"))
          groupCandidateListStandard.add(groups[i]);
        else
          groupCandidateListSpecial.add(groups[i]);
      }
     
      if(!groupCandidateListSpecial.contains("selectiveCacheUpdateNonApplicable"))
      {
        groupCandidateListSpecial.addAll(groupCandidateListStandard);
      }
      String[] newGroups = new String[groupCandidateListSpecial.size()];
      groups = groupCandidateListSpecial.toArray(newGroups);
    }
   
    if(CmsPropertyHandler.getUseSynchronizationOnCaches())
    {
        synchronized(cacheAdministrator) //Back
        {
        try
        {
          if(useGroups)
          {
            if(CmsPropertyHandler.getUseHashCodeInCaches())
              cacheAdministrator.putInCache("" + key.toString().hashCode(), value, groups);
            else
              cacheAdministrator.putInCache(key.toString(), value, groups);
          }
          else
          {
            if(CmsPropertyHandler.getUseHashCodeInCaches())
              cacheAdministrator.putInCache("" + key.toString().hashCode(), value);
            else
                cacheAdministrator.putInCache(key.toString(), value);
          }
        }
        catch (Exception e)
        {
          logger.warn("Error putting in cache:" + e.getMessage());
        }
      }
    }
    else
    {
      try
      {
        if(useGroups)
        {
          if(CmsPropertyHandler.getUseHashCodeInCaches())
            cacheAdministrator.putInCache("" + key.toString().hashCode(), value, groups);
          else
            cacheAdministrator.putInCache(key.toString(), value, groups);
        }
        else
        {
          if(CmsPropertyHandler.getUseHashCodeInCaches())
            cacheAdministrator.putInCache("" + key.toString().hashCode(), value);
          else
              cacheAdministrator.putInCache(key.toString(), value);
        }
      }
      catch (Exception e)
      {
        logger.warn("Error putting in cache:" + e.getMessage(), e);
View Full Code Here

      Object value = null;
      boolean stopUseFileCacheFallback = false;
     
      //synchronized(caches)
      //{
        GeneralCacheAdministrator cacheAdministrator = (GeneralCacheAdministrator)caches.get(cacheName);
        if(cacheAdministrator != null)
        {
          //TODO
          if(CmsPropertyHandler.getUseSynchronizationOnCaches())
        {
            synchronized(cacheAdministrator) //Back
            {
                try
              {
                if(CmsPropertyHandler.getUseHashCodeInCaches())
                value = (cacheAdministrator == null) ? null : cacheAdministrator.getFromCache("" + key.hashCode(), CacheEntry.INDEFINITE_EXPIRY);
              else
                value = (cacheAdministrator == null) ? null : cacheAdministrator.getFromCache(key, CacheEntry.INDEFINITE_EXPIRY);

                //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Getting from cache on " + cacheName, t.getElapsedTime());
              }
              catch (NeedsRefreshException nre)
              {
                if(useFileCacheFallback && nre.getCacheContent() != null)
                {
                  stopUseFileCacheFallback = true;
                }
               
                try
                {
                if(CmsPropertyHandler.getUseHashCodeInCaches())
                  cacheAdministrator.cancelUpdate("" + key.hashCode());
                else
                  cacheAdministrator.cancelUpdate(key);
                }
                catch (Exception e)
                {
                  logger.error("Error:" + e.getMessage());
              }

                //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Getting object 3 part 2 from " + cacheName, t.getElapsedTime());
            }
            }
        }
          else
          {
            try
            {
            if(CmsPropertyHandler.getUseHashCodeInCaches())
              value = (cacheAdministrator == null) ? null : cacheAdministrator.getFromCache("" + key.hashCode(), CacheEntry.INDEFINITE_EXPIRY);
            else
              value = (cacheAdministrator == null) ? null : cacheAdministrator.getFromCache(key, CacheEntry.INDEFINITE_EXPIRY);
            }
            catch (NeedsRefreshException nre)
            {
              if(useFileCacheFallback && nre.getCacheContent() != null)
              {
                stopUseFileCacheFallback = true;
              }
             
              try
              {
              if(CmsPropertyHandler.getUseHashCodeInCaches())
                cacheAdministrator.cancelUpdate("" + key.hashCode());
              else
                cacheAdministrator.cancelUpdate(key);
              }
              catch (Exception e)
              {
                logger.error("Error:" + e.getMessage());
            }
View Full Code Here

     
      String pageKey = key;
      //if(CmsPropertyHandler.getUseHashCodeInCaches())
      //  pageKey = "" + key.hashCode();

      GeneralCacheAdministrator cacheAdministrator = (GeneralCacheAdministrator)caches.get(cacheName);
      if(cacheAdministrator == null)
      {
        Map cacheSettings = (Map)getCachedObject("serverNodePropertiesCacheSettings", "cacheSettings");
        if(cacheSettings == null)
        {
          cacheSettings = CmsPropertyHandler.getCacheSettings();
          cacheObject("serverNodePropertiesCacheSettings", "cacheSettings", cacheSettings);
        }
       
        String cacheCapacity = "20000";
        String cacheCapacityProperty = (String)cacheSettings.get("CACHE_CAPACITY_" + cacheName);
        if(cacheCapacityProperty != null && !cacheCapacityProperty.equals(""))
          cacheCapacity = cacheCapacityProperty;
         
      if(cacheCapacity != null && !cacheCapacity.equals(""))
        {
        Properties p = new Properties();
         
        logger.info("Creating cache " + cacheName + " with:" + cacheCapacity);
        p.setProperty(AbstractCacheAdministrator.CACHE_ALGORITHM_KEY, "com.opensymphony.oscache.base.algorithm.ImprovedLRUCache");
        p.setProperty(AbstractCacheAdministrator.CACHE_CAPACITY_KEY, cacheCapacity);
        cacheAdministrator = new GeneralCacheAdministrator(p);
      }
      else
      {
        cacheAdministrator = new GeneralCacheAdministrator();
        logger.info("Creating cache without limit" + cacheName);
      }
     
      if(cacheAdministrator.getCache().cacheMap instanceof ImprovedLRUCache)
        ((ImprovedLRUCache)cacheAdministrator.getCache().cacheMap).setIsPageCache(true);
     
      CacheEntryEventListenerImpl cacheEntryEventListener = new ExtendedCacheEntryEventListenerImpl();
      CacheMapAccessEventListenerImpl cacheMapAccessEventListener = new CacheMapAccessEventListenerImpl();
         
          cacheAdministrator.getCache().addCacheEventListener(cacheEntryEventListener, CacheEntryEventListener.class);
      cacheAdministrator.getCache().addCacheEventListener(cacheMapAccessEventListener, CacheMapAccessEventListener.class);
      caches.put(cacheName, cacheAdministrator);
      //locksCache.put(cacheName, new ReentrantReadWriteLock());
      }
     
     
View Full Code Here

TOP

Related Classes of com.opensymphony.oscache.general.GeneralCacheAdministrator

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.