Package com.opensymphony.oscache.general

Examples of com.opensymphony.oscache.general.GeneralCacheAdministrator


    if(getDefeatCaches().getDefeatCache())
      return null;
   
    Map<String,Object> cachedValues = new HashMap<String,Object>();
   
    GeneralCacheAdministrator cacheAdministrator = (GeneralCacheAdministrator)caches.get(cacheName);
    if(cacheAdministrator != null)
    {
        synchronized(cacheAdministrator) //Back
        {
          try
          {
            if(cacheAdministrator != null)
            {
              for(String key : (Set<String>)cacheAdministrator.getCache().cacheMap.keySet())
              {
                if(key.toString().endsWith(keyNameFilter))
                {
                  try
                    {
                    cachedValues.put(key, cacheAdministrator.getCache().getFromCache(key));
                    }
                  catch (NeedsRefreshException nre)
                  {
                    logger.info("Stale cache entry");
                      cacheAdministrator.cancelUpdate(key);
                }
                }
              }
            }
          }
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())
          {
              try
            {
                if(CmsPropertyHandler.getUseHashCodeInCaches())
                  value = (cacheAdministrator == null) ? null : cacheAdministrator.getFromCache("" + key.hashCode(), updateInterval);
                else
                  value = (cacheAdministrator == null) ? null : cacheAdministrator.getFromCache(key, updateInterval);
            }
            catch (NeedsRefreshException nre)
            {
              if(useFileCacheFallback && nre.getCacheContent() != null)
              {
                stopUseFileCacheFallback = true;
              }
             
                if(CmsPropertyHandler.getUseHashCodeInCaches())
                  cacheAdministrator.cancelUpdate("" + key.hashCode());
                else
                  cacheAdministrator.cancelUpdate(key);
          }
          }
          else
          {
            try
            {
                if(CmsPropertyHandler.getUseHashCodeInCaches())
                  value = (cacheAdministrator == null) ? null : cacheAdministrator.getFromCache("" + key.hashCode(), updateInterval);
                else
                  value = (cacheAdministrator == null) ? null : cacheAdministrator.getFromCache(key, updateInterval);
            }
            catch (NeedsRefreshException nre)
            {
              if(useFileCacheFallback && nre.getCacheContent() != null)
              {
                stopUseFileCacheFallback = true;
              }
             
                if(CmsPropertyHandler.getUseHashCodeInCaches())
                  cacheAdministrator.cancelUpdate("" + key.hashCode());
                else
                  cacheAdministrator.cancelUpdate(key);
          }
          }
         
        if(useFileCacheFallback && !stopUseFileCacheFallback)
          {               
View Full Code Here

              }
            }
          }
          else
          {
              GeneralCacheAdministrator cacheInstance = (GeneralCacheAdministrator)e.getValue();
            synchronized(cacheInstance)
            {
              pageCacheNotifications.add(entityName + "_" + entityId);

              Set<String> entries = cacheInstance.getCache().getGroup(entityName + "_" + entityId);
              logger.info("entries:" + entries.size());
              for(String entry : entries)
              {
                //debug.append("" + cachName + "=" + entry + ",");
                entriesToClear.add(new String[]{cachName, entry});
              }
             
              try
              {
                pageCacheNotifications.add("selectiveCacheUpdateNonApplicable");

                if(entityName.toLowerCase().equals("content"))
                {
                  List<ContentTypeDefinitionVO> contentTypeDefinitionVOList = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOList();
                  for(ContentTypeDefinitionVO ctdVO : contentTypeDefinitionVOList)
                  {
                    //System.out.println("Group:" + "selectiveCacheUpdateNonApplicable_contentTypeDefinitionId_" + ctdVO.getId());
                    Set<String> selectiveCacheUpdateNonApplicableEntries = cacheInstance.getCache().getGroup("selectiveCacheUpdateNonApplicable_contentTypeDefinitionId_" + ctdVO.getId());
                    for(String entry : selectiveCacheUpdateNonApplicableEntries)
                    {
                      //debug.append("selectiveCacheUpdateNonApplicable_contentTypeDefinitionId_" + ctdVO.getId() + "/" + cachName + "=" + entry + ",");
                      //debug.append("selectiveCacheUpdateNonApplicable_contentTypeDefinitionId_" + ctdVO.getId() + ",");
                      entriesToClear.add(new String[]{cachName, entry});
                      pageCacheNotifications.add("selectiveCacheUpdateNonApplicable_contentTypeDefinitionId_" + ctdVO.getId());
                    }
                  }
                }
                Set<String> selectiveCacheUpdateNonApplicableEntries = cacheInstance.getCache().getGroup("selectiveCacheUpdateNonApplicable");
                for(String entry : selectiveCacheUpdateNonApplicableEntries)
                {
                  //debug.append("selectiveCacheUpdateNonApplicable: " + cachName + "=" + entry + ",");
                  entriesToClear.add(new String[]{cachName, entry});
                  pageCacheNotifications.add("selectiveCacheUpdateNonApplicable");
View Full Code Here

            cacheSize = cacheInstance.size();
          }
        }
        else
        {
            GeneralCacheAdministrator cacheInstance = (GeneralCacheAdministrator)object;
            synchronized(cacheInstance) //Back
            {
            /*
            Timer t = new Timer();
            ReentrantReadWriteLock rwl = locksCache.get(cacheName);
            boolean lockSuccess = false;
            try {
              System.out.println("YAAAAAAAAAAAAA 2");
            lockSuccess = rwl.readLock().tryLock(readLockTimeout, TimeUnit.SECONDS);
          } catch (InterruptedException e1) {
            RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Error getting lock in getCacheSize on " + cacheName, t.getElapsedTime());
            printLockDebug(rwl);
            return 0;
          }
            //rwl.readLock().lock();
                try
                {
                  if(!lockSuccess)
                  {
              RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Timeout getting lock in getCacheSize on " + cacheName, t.getElapsedTime());
                    return 0;
                  }
            */ 
            cacheSize = cacheInstance.getCache().getSize();
           
              //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Getting getCacheSize on " + cacheName, t.getElapsedTime());
          }
            /*
                finally
View Full Code Here

            cacheInstance.clear();
          }
        }
        else
        {
            GeneralCacheAdministrator cacheInstance = (GeneralCacheAdministrator)object;
            synchronized(cacheInstance) //Back
            {
            /* 
            Timer t = new Timer();
            ReentrantReadWriteLock rwl = locksCache.get(cacheName);
            boolean lockSuccess = false;
            try {
            lockSuccess = rwl.writeLock().tryLock(writeLockTimeout, TimeUnit.SECONDS);
            printLockDebug(rwl);
          } catch (InterruptedException e1) {
            return;
          }
            //rwl.writeLock().lock();
                try
                {
                  if(!lockSuccess)
                  {
              printLockDebug(rwl);
                    return;
                  }
             
              RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Getting lock for flushing " + cacheName, t.getElapsedTime());
                  */
            cacheInstance.flushAll();
              cacheInstance.destroy();

              //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Flushing " + cacheName, t.getElapsedTime());
          }
            /*
                finally
View Full Code Here

            cacheInstance.clear();
          }
        }
        else
        {
            GeneralCacheAdministrator cacheInstance = (GeneralCacheAdministrator)object;
            synchronized(cacheInstance) //Back
            {
            /*
            Timer t = new Timer();
            ReentrantReadWriteLock rwl = locksCache.get(cacheName);
            boolean lockSuccess = false;
            try {
              System.out.println("ddddddddddddddddddd");
              lockSuccess = rwl.writeLock().tryLock(writeLockTimeout, TimeUnit.SECONDS);
          } catch (InterruptedException e1) {
            printLockDebug(rwl);
            return;
          }
            //rwl.writeLock().lock();
                try
                {
                  if(!lockSuccess)
                  {
              printLockDebug(rwl);
                    return;
                  }

              RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Getting lock for flushing " + cacheName, t.getElapsedTime());
            */
            cacheInstance.flushAll();
           
              //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Flushing " + cacheName, t.getElapsedTime());
          }
            /*
                finally
View Full Code Here

            cacheInstance.remove(key);
          }
        }
        else
        {
            GeneralCacheAdministrator cacheInstance = (GeneralCacheAdministrator)object;
            synchronized(cacheInstance) //Back
            {
            cacheInstance.flushEntry(key);
          }
        }
      }
    //}
  }
View Full Code Here

          cacheInstance.remove(key);
        }
      }
      else
      {
          GeneralCacheAdministrator cacheInstance = (GeneralCacheAdministrator)object;
          synchronized(cacheInstance) //Back
          {
          //cacheInstance.flushEntry(key);
          cacheInstance.removeEntry(key);
          }
      }
    }
  }
View Full Code Here

            logger.info("Clearing full cache:" + cacheName + " - the call wanted partly clear for [" + group + "] but the cache was a Map.");
          }
        }
        else
        {
            GeneralCacheAdministrator cacheInstance = (GeneralCacheAdministrator)object;
            synchronized(cacheInstance) //Back
            {
            /* 
            Timer t = new Timer();
            ReentrantReadWriteLock rwl = locksCache.get(cacheName);
            boolean lockSuccess = false;
            try {
              System.out.println("YEEEEEEEEEEEEEEEEEAAAAAAH");
            lockSuccess = rwl.writeLock().tryLock(writeLockTimeout, TimeUnit.SECONDS);
            printLockDebug(rwl);
          } catch (InterruptedException e1) {
            return;
          }
            //rwl.writeLock().lock();
                try
                {
                  if(!lockSuccess)
                  {
                    return;
                  }

              RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Getting lock for flushGroup in " + cacheName, t.getElapsedTime());
          */
              cacheInstance.flushGroup(group);

            //  RequestAnalyser.getRequestAnalyser().registerComponentStatistics("FlushGroup on " + cacheName, t.getElapsedTime());
          }
            /*
                finally
View Full Code Here

                cacheInstance.clear();
              }
            }
            else
            {
                GeneralCacheAdministrator cacheInstance = (GeneralCacheAdministrator)e.getValue();
              synchronized(cacheInstance)
              {
                  cacheInstance.flushAll();
              }
            }
            logger.info("Cleared cache:" + e.getKey());
           
              i.remove();
          }
        }
      //}
    }
      else if(entity.equalsIgnoreCase("CacheNames"))
      {
        String[] cacheNames = entityId.split(",");
        for(int i=0; i<cacheNames.length; i++)
        {
          String cacheName = cacheNames[i];
          CacheController.clearCache(cacheName);
        }
      }
    else
    {
      logger.info("Clearing some caches");
      logger.info("entity:" + entity);

        String useSelectivePageCacheUpdateString = CmsPropertyHandler.getUseSelectivePageCacheUpdate();
        boolean useSelectivePageCacheUpdate = false;
        if(useSelectivePageCacheUpdateString != null && useSelectivePageCacheUpdateString.equalsIgnoreCase("true"))
            useSelectivePageCacheUpdate = true;
           
        String operatingMode = CmsPropertyHandler.getOperatingMode();

        TreeMap<String, Object> orderedCaches = new TreeMap<String,Object>(new CacheComparator());
        orderedCaches.putAll(caches);
       
        /*
        for (String key : orderedCaches.keySet())
      {
        System.out.println("key:" + key);
      }
      */
        //t.printElapsedTime("Start cache eviction");
        RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Start cache eviction", t.getElapsedTime());
        //t.printElapsedTime("START cachesLoop:" + entity + ":" + entityId);

      //synchronized(caches)
        //{
          //for (Iterator i = caches.entrySet().iterator(); i.hasNext(); )
          cachesLoop:for (Iterator i = orderedCaches.entrySet().iterator(); i.hasNext(); )
        {
          RequestAnalyser.getRequestAnalyser().registerComponentStatistics("cache iteration top", t.getElapsedTime());

          Map.Entry e = (Map.Entry) i.next();
          logger.info("e:" + e.getKey());

          boolean clear = false;
          boolean selectiveCacheUpdate = false;
          String cacheName = e.getKey().toString();

          if(cachesToSkip != null)
          {
            for(int index=0; index<cachesToSkip.length; index++)
            {
                if(cacheName.equals(cachesToSkip[index]))
                {
                    continue cachesLoop;
                }
            }
          }
         
          //t.printElapsedTime("clearCaches 3");

          if(cacheName.equalsIgnoreCase("serviceDefinitionCache") && entity.indexOf("ServiceBinding") > 0)
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("qualifyerListCache") && (entity.indexOf("Qualifyer") > 0 || entity.indexOf("ServiceBinding") > 0))
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("availableServiceBindingCache") && entity.indexOf("AvailableServiceBinding") > 0)
          { 
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("categoriesCache") && entity.indexOf("Category") > 0)
          { 
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("repositoryCache") && entity.indexOf("Repository") > 0)
          { 
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("languageCache") && entity.indexOf("Language") > 0)
          { 
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("localeCache") && entity.indexOf("Language") > 0)
          { 
            clear = true;
          }
          if((cacheName.equalsIgnoreCase("latestSiteNodeVersionCache") || cacheName.equalsIgnoreCase("pageCacheLatestSiteNodeVersions") || cacheName.equalsIgnoreCase("pageCacheSiteNodeTypeDefinition")) && entity.indexOf("SiteNode") > 0)
          { 
            clear = true;
            selectiveCacheUpdate = true;
          }
          if((cacheName.equalsIgnoreCase("parentSiteNodeCache") || cacheName.equalsIgnoreCase("pageCacheParentSiteNodeCache")) && entity.indexOf("SiteNode") > 0)
          { 
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("NavigationCache") && (entity.indexOf("SiteNode") > 0 || entity.indexOf("Content") > 0))
          { 
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("pagePathCache") && (entity.indexOf("SiteNode") > 0 || entity.indexOf("Content") > 0))
          { 
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("componentEditorCache") && (entity.indexOf("SiteNode") > 0 || entity.indexOf("Content") > 0))
          { 
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("componentEditorVersionIdCache") && (entity.indexOf("SiteNode") > 0 || entity.indexOf("Content") > 0))
          { 
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("masterLanguageCache") && (entity.indexOf("Repository") > 0 || entity.indexOf("Language") > 0))
          { 
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("parentRepository") && entity.indexOf("Repository") > 0)
          { 
            clear = true;
          }
          if(cacheName.startsWith("contentAttributeCache") && (entity.indexOf("Content") > -1 || entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0))
          { 
            clear = true;
            selectiveCacheUpdate = true;
          }
          if(cacheName.startsWith("metaInfoContentAttributeCache") && entity.indexOf("Content") > -1)
          { 
            clear = true;
            selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("contentVersionCache") && (entity.indexOf("Content") > -1 || entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0))
          { 
            clear = true;
            selectiveCacheUpdate = true;
          }
          if(cacheName.startsWith("contentVersionIdCache") && (entity.indexOf("Content") > -1 || entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0))
          { 
            clear = true;
            selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("referencingPagesCache") && (entity.indexOf("ContentVersion") > -1 || entity.indexOf("Qualifyer") > 0))
          { 
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("boundSiteNodeCache") && (entity.indexOf("ServiceBinding") > 0 || entity.indexOf("Qualifyer") > 0 || entity.indexOf("SiteNodeVersion") > 0 || entity.indexOf("SiteNodeVersion") > 0 || entity.indexOf("SiteNode") > 0 || entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0))
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("boundContentCache") && (entity.indexOf("ServiceBinding") > 0 || entity.indexOf("Qualifyer") > 0 || entity.indexOf("SiteNodeVersion") > 0 || entity.indexOf("ContentVersion") > 0 || entity.indexOf("Content") > 0 || entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0))
          {
            clear = true;
          }
          if(cacheName.startsWith("pageCache") && entity.indexOf("Registry") == -1)
          { 
            clear = true;
            selectiveCacheUpdate = true;
          }
          if(cacheName.startsWith("pageCacheExtra") && entity.indexOf("Registry") == -1)
          { 
            clear = true;
            selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("componentCache") && entity.indexOf("Registry") == -1)
          { 
            clear = true;
            selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("componentPropertyCache") && (entity.indexOf("SiteNode") > -1 || entity.indexOf("ContentVersion") > -1 || entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0))
          { 
            clear = true;
            //selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("componentPropertyVersionIdCache") && (entity.indexOf("SiteNode") > -1 || entity.indexOf("ContentVersion") > -1 || entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0))
          { 
            clear = true;
            //selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("componentPropertyCacheRepoGroups") && (entity.indexOf("SiteNode") > -1 || entity.indexOf("ContentVersion") > -1 || entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0))
          { 
            clear = true;
            if(entity.indexOf("SiteNode") > -1 || entity.indexOf("ContentVersion") > -1)
              selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("componentPropertyVersionIdCacheRepoGroups") && (entity.indexOf("SiteNode") > -1 || entity.indexOf("ContentVersion") > -1 || entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0))
          { 
            clear = true;
            if(entity.indexOf("SiteNode") > -1 || entity.indexOf("ContentVersion") > -1)
              selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("pageComponentsCache") && (entity.indexOf("ContentVersion") > -1 || entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0))
          { 
            clear = true;
            //selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("includeCache"))
          { 
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("authorizationCache") && (entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0 || entity.indexOf("Intercept") > 0))
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("personalAuthorizationCache") && (entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0 || entity.indexOf("Intercept") > 0))
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("componentPaletteDivCache") && (entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0))
          { 
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("userCache") && (entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0))
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("principalCache") && (entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0))
          {
            clear = true;
          }
          if((cacheName.equalsIgnoreCase("assetUrlCache") || cacheName.equalsIgnoreCase("assetUrlCacheWithGroups") || cacheName.equalsIgnoreCase("assetThumbnailUrlCache")) && (entity.indexOf("DigitalAsset") > 0 || entity.indexOf("ContentVersion") > 0 || entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0))
          {
            clear = true;
            if(cacheName.equalsIgnoreCase("assetUrlCacheWithGroups") && (entity.indexOf("ContentVersion") > -1 || entity.indexOf("DigitalAsset") > -1))
              selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("digitalAssetCache") && (entity.indexOf("DigitalAsset") > 0 || entity.indexOf("ContentVersion") > 0))
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("sortedChildContentsCache") && (entity.indexOf("Content") > 0 || entity.indexOf("ContentVersion") > 0 || entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0))
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("childContentCache") && (entity.indexOf("Content") > 0 || entity.indexOf("ContentVersion") > 0 || entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0))
          {
            clear = true;
            selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("matchingContentsCache") && (entity.indexOf("Content") > 0 || entity.indexOf("ContentVersion") > 0 || entity.indexOf("AccessRight") > 0 || entity.indexOf("SystemUser") > 0 || entity.indexOf("Role") > || entity.indexOf("Group") > 0))
          {
            clear = true;
            selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("workflowCache") && entity.indexOf("WorkflowDefinition") > 0)
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("rootSiteNodeCache") && entity.indexOf("SiteNode") > 0)
          {
            if(CmsPropertyHandler.getOperatingMode().equals("0"))
              clear = true;
          }
          if((cacheName.equalsIgnoreCase("siteNodeCache") || cacheName.equalsIgnoreCase("siteNodeVOCache")) && entity.indexOf("SiteNode") > 0)
          {
            clear = true;
            selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("contentCache") && entity.indexOf("Content") > 0)
          {
            clear = true;
            selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("rootContentCache") && entity.indexOf("Content") > 0)
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("componentContentsCache") && entity.indexOf("Content") > 0)
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("childSiteNodesCache") && (entity.indexOf("SiteNode") > 0 || entity.indexOf("ContentVersion") > 0))
          {
            clear = true;
            selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("childPagesCache") && (entity.indexOf("SiteNode") > 0 || entity.indexOf("Content") > 0))
          {
            clear = true;
            selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("siteNodeCacheWithLatestVersion") && entity.indexOf("SiteNode") > 0)
          {
            clear = true;
            selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("propertySetCache") && entity.indexOf("SiteNode") > 0)
          {
              clear = true;
          }
          if(cacheName.equalsIgnoreCase("groupVOListCache") && entity.indexOf("Group") > 0)
          {               
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("roleListCache") && entity.indexOf("Role") > 0)
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("groupPropertiesCache") && (entity.indexOf("Group") > 0 || entity.indexOf("PropertiesCategory") > 0))
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("propertiesCategoryCache") && (entity.indexOf("Group") > 0 || entity.indexOf("Role") > 0 || entity.indexOf("User") > 0 || entity.indexOf("PropertiesCategory") > 0))
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("rolePropertiesCache") && entity.indexOf("Role") > 0)
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("principalPropertyValueCache") && (entity.indexOf("Group") > 0 || entity.indexOf("Role") > 0 || entity.indexOf("User") > 0))
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("relatedCategoriesCache") && (entity.indexOf("Group") > 0 || entity.indexOf("Role") > 0 || entity.indexOf("User") > 0 || entity.indexOf("PropertiesCategory") > 0))
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("categoryCache") && entity.indexOf("Category") > 0)
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("contentCategoryCache") && entity.indexOf("ContentVersion") > 0)
          {
            clear = true;
            selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("redirectCache") && entity.indexOf("Redirect") > 0)
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("interceptorsCache") && entity.indexOf("Intercept") > 0)
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("interceptionPointCache") && entity.indexOf("Intercept") > 0)
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("siteNodeLanguageCache") && (entity.indexOf("Repository") > 0 || entity.indexOf("Language") > 0 || entity.indexOf("SiteNode") > 0))
          {
            clear = true;
            selectiveCacheUpdate = true;
          }
          if(cacheName.equalsIgnoreCase("contentTypeDefinitionCache") && entity.indexOf("ContentTypeDefinition") > 0)
          {
            clear = true;
          }
          if(cacheName.equalsIgnoreCase("ServerNodeProperties"))
          {
            clear = true;
          }
         
          if(!cacheName.equalsIgnoreCase("serverNodePropertiesCache") && entity.equalsIgnoreCase("ServerNodeProperties"))
          {
            clear = true;           
          }
          if(!cacheName.equalsIgnoreCase("encodedStringsCache") && entity.equalsIgnoreCase("ServerNodeProperties"))
          {
            clear = true;           
          }

          if(logger.isInfoEnabled())
            logger.info("clear:" + clear);

          if(clear)
          { 
            if(logger.isInfoEnabled())
                logger.info("clearing:" + e.getKey());

            Object object = e.getValue();
           
            String sentContentId = null;
            String sentParentContentId = null;
            String sentSiteNodeId = null;
            String sentParentSiteNodeId = null;
            String sentRepositoryId = null;
            String sentContentTypeDefinitionId = null;
            String sentContentIsProtected = null;
            if (extraInformation != null)
            {
              sentContentId = extraInformation.get("contentId");
              sentParentContentId = extraInformation.get("parentContentId");
              sentSiteNodeId = extraInformation.get("siteNodeId");
              sentParentSiteNodeId = extraInformation.get("parentSiteNodeId");
              sentRepositoryId = extraInformation.get("repositoryId");
              sentContentTypeDefinitionId = extraInformation.get("contentTypeDefinitionId");
              sentContentIsProtected = extraInformation.get("contentIsProtected");
            }
           
            //System.out.println("sentContentId:" + sentContentId);
            //System.out.println("sentParentContentId:" + sentParentContentId);
            //System.out.println("sentSiteNodeId:" + sentSiteNodeId);
            //System.out.println("sentParentSiteNodeId:" + sentParentSiteNodeId);
            //System.out.println("sentRepositoryId:" + sentRepositoryId);

            if(object instanceof Map)
            {
              Map cacheInstance = (Map)e.getValue();
                synchronized(cacheInstance)
              {
                  if(cacheName.equals("componentContentsCache"))
                  {
                    try
                    {
                      if(entity.indexOf("ContentVersion") > 0)
                      {
                        String contentId = sentContentId;
                        String contentTypeDefinitionId = sentContentTypeDefinitionId;
                        if(contentId == null || contentId.equals(""))
                        {
                          try
                          {
                            contentId = ""+ContentVersionController.getContentVersionController().getContentIdForContentVersion(new Integer(entityId));
                          }
                          catch (Exception e2)
                          {
                            logger.info("Error loading content with id " + entityId + ":" + e2.getMessage());
                        }
                        }
                       
                       
                        if(contentId != null)
                        {                             
                          //ContentVO contentVO = ContentController.getContentController().getContentVOWithId(contentId);
                          if(contentTypeDefinitionId != null && !contentTypeDefinitionId.equals(""))
                          {
                            ContentTypeDefinitionVO ctdVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(new Integer(contentTypeDefinitionId));
                            if(ctdVO.getName().equals("HTMLTemplate") || ctdVO.getName().equals("PagePartTemplate"))
                            {
                            ComponentController.getController().reIndexComponentContentsDelayed(new Integer(contentId));
                            }
                          }
                          else
                            logger.info("No content type for " + contentId);
                        }
                      }
                      else
                        logger.info("skipping clearing components as it seems stupid");
                    }
                    catch (Exception e2)
                    {
                      logger.warn("Error clearing componentContentsCache:" + e2.getMessage(), e2);
                  }
                  }
                  else if(!(cacheName.equals("userAccessCache") && cacheInstance.size() < 100))
                  {
                    logger.info("clearing ordinary map:" + e.getKey() + " (" + cacheInstance.size() + ")");
                    cacheInstance.clear();
                  }
                  else
                    logger.info("skipping clearing this as it seems stupid");
                }
            }
            else
            {
                GeneralCacheAdministrator cacheInstance = (GeneralCacheAdministrator)e.getValue();
                synchronized(cacheInstance) //Back
                {
                  //t.printElapsedTime("START:" + entity + ":" + entityId);
                  //ADD logic to flush correct on sitenode and sitenodeversion
                  /*
                  if(selectiveCacheUpdate && entity.indexOf("SiteNode") > 0)
                  {
                    cacheInstance.flushAll();
                    eventListeners.remove(cacheName + "_cacheEntryEventListener");
                    eventListeners.remove(cacheName + "_cacheMapAccessEventListener");
                    logger.info("clearing:" + e.getKey());
                  }
                  */
                  //System.out.println("entity:" + entity);
                if(entity.indexOf("pageCache") == 0)
                  {
                  if(entity.indexOf("pageCache:") == 0)
                  {
                    String groupQualifyer = entity.substring("pageCache:".length());
                    logger.info("CacheController: This is a application pageCache-clear request... specific:" + groupQualifyer);
                    logger.info("clearing " + e.getKey() + " : " + groupQualifyer);

                    PageCacheHelper.getInstance().notify("" + groupQualifyer);
                      /*
                    if(cacheName.equals("pageCacheExtra"))
                      {
                        clearFileCacheForGroup(cacheInstance, "" + groupQualifyer);
                      }
                      else if(cacheName.equals("pageCache"))
                      {
                        cacheInstance.flushGroup("" + groupQualifyer);                     
                      }
                      */
                  }
                  else
                    {
                    PageCacheHelper.getInstance().notify("selectiveCacheUpdateNonApplicable");
                    /*
                      logger.error("clearing " + e.getKey() + " selectiveCacheUpdateNonApplicable");
                      if(cacheName.equals("pageCacheExtra"))
                      {
                        clearFileCacheForGroup(cacheInstance, "selectiveCacheUpdateNonApplicable");
                      }
                      else if(cacheName.equals("pageCache"))
                      {
                        cacheInstance.flushGroup("selectiveCacheUpdateNonApplicable");                     
                      }
                      */
                    }
                  }

                if(selectiveCacheUpdate && entity.indexOf("Repository") > 0 && useSelectivePageCacheUpdate)
                  {
                    if(cacheName.equals("pageCacheExtra"))
                    {
                      PageCacheHelper.getInstance().notify("repository_" + entityId);
                      PageCacheHelper.getInstance().notify("selectiveCacheUpdateNonApplicable");
                    }
                    else
                    {
                      cacheInstance.flushGroup("repository_" + entityId);
                      cacheInstance.flushGroup("selectiveCacheUpdateNonApplicable");                     
                    }
                   
                    /*
                    logger.info("clearing " + e.getKey() + " with group " + "repository_" + entityId);
                    if(cacheName.equals("pageCacheExtra"))
                    {
                      clearFileCacheForGroup(cacheInstance, "repository_" + entityId);
                      clearFileCacheForGroup(cacheInstance, "selectiveCacheUpdateNonApplicable");
                    }
                    else
                    {
                      cacheInstance.flushGroup("repository_" + entityId);
                      cacheInstance.flushGroup("selectiveCacheUpdateNonApplicable");                     
                    }
                    */
                  }
                  else if(selectiveCacheUpdate && entity.indexOf("SiteNodeVersion") > 0)
                  {
                    //Thread.dumpStack();
                    //How to solve this good
                    if(CmsPropertyHandler.getOperatingMode().equalsIgnoreCase("0"))
                    {
                      if(cacheName.equals("pageCacheExtra"))
                      {
                        PageCacheHelper.getInstance().notify("siteNodeVersion_" + entityId);
                        PageCacheHelper.getInstance().notify("selectiveCacheUpdateNonApplicable");

                        //clearFileCacheForGroup(cacheInstance, "siteNodeVersion_" + entityId);
                        //clearFileCacheForGroup(cacheInstance, "selectiveCacheUpdateNonApplicable");
                      }
                      else
                      {
                        cacheInstance.flushGroup("siteNodeVersion_" + entityId);
                        cacheInstance.flushGroup("selectiveCacheUpdateNonApplicable");
                      }
                      logger.info("clearing " + e.getKey() + " with group " + "siteNodeVersion_" + entityId);
                     
                      try
                      {
                        logger.info("BeforesiteNodeVersionVO...");
                       
                        String siteNodeId = sentSiteNodeId;
                        String repositoryId = sentRepositoryId;
                        String parentSiteNodeId = sentParentSiteNodeId;
                        //System.out.println("siteNodeId:" + siteNodeId);
                        //System.out.println("repositoryId:" + repositoryId);
                        //System.out.println("parentSiteNodeId:" + parentSiteNodeId);
                        if(siteNodeId == null || siteNodeId.equals(""))
                        {
                          try
                          {
                            SiteNodeVersionVO snvVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(new Integer(entityId));
                            siteNodeId = ""+snvVO.getSiteNodeId();
                            if(repositoryId == null)
                            {
                              SiteNodeVO snVO = SiteNodeController.getController().getSiteNodeVOWithId(snvVO.getSiteNodeId());
                              repositoryId = ""+snVO.getRepositoryId();
                              parentSiteNodeId = ""+snVO.getParentSiteNodeId();
                            }
                          }
                          catch (Exception e2)
                          {
                            logger.info("Error getting siteNodeVersion " + entityId);
                          }
                        }
                                               
                        if(siteNodeId != null)
                        {
                          logger.info("Before flushGroup2...");
                          if(cacheName.equals("pageCacheExtra"))
                          {
                            PageCacheHelper.getInstance().notify("siteNode_" + siteNodeId);
                            //clearFileCacheForGroup(cacheInstance, "siteNode_" + siteNodeId);
                          }
                          else
                          {
                            cacheInstance.flushGroup("siteNode_" + siteNodeId);
                            cacheInstance.flushGroup("" + siteNodeId);
                          }
                         
                          if(siteNodeId != null && (cacheName.equals("childSiteNodesCache") || cacheName.equals("childPagesCache") || cacheName.equals("siteNodeCache") || cacheName.equals("componentPropertyCacheRepoGroups") || cacheName.equals("componentPropertyVersionIdCacheRepoGroups")))
                          {
                            if(cacheName.equals("componentPropertyCacheRepoGroups") || cacheName.equals("componentPropertyVersionIdCacheRepoGroups"))
                            {
                              cacheInstance.flushGroup("" + repositoryId);
                              logger.info("Clearing componentPropertyCacheRepoGroups for repo:" + repositoryId);
                            }
                            if(parentSiteNodeId != null)
                            {
                              cacheInstance.flushGroup("siteNode_" + parentSiteNodeId);
                              cacheInstance.flushGroup("" + parentSiteNodeId);
                              cacheInstance.flushEntry("" + parentSiteNodeId);
                              logger.info("Clearing for:" + parentSiteNodeId);
                            }
                          }
                         
                          logger.info("After flushGroup2...");
                        }
                      }
                      catch(Exception se)
                      {
                        logger.warn("Missing siteNode version: " + se.getMessage(), se);
                      }
                    }
                    else
                    {
                      try
                      {
                        if((cacheName.equals("childSiteNodesCache") || cacheName.equals("childPagesCache") || cacheName.equals("siteNodeCache") || cacheName.equals("componentPropertyCacheRepoGroups") || cacheName.equals("componentPropertyVersionIdCacheRepoGroups")))
                        {
                          SiteNodeVersionVO snvVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(new Integer(entityId));
                          SiteNodeVO snVO = SiteNodeController.getController().getSiteNodeVOWithId(snvVO.getSiteNodeId());
                         
                          Integer repositoryId = snVO.getRepositoryId();
                          Integer parentSiteNodeId = snVO.getParentSiteNodeId();
 
                          if(cacheName.equals("componentPropertyCacheRepoGroups") || cacheName.equals("componentPropertyVersionIdCacheRepoGroups"))
                          {
                            cacheInstance.flushGroup("" + repositoryId);
                            logger.info("Clearing componentPropertyCacheRepoGroups for repo:" + repositoryId);
                          }
                          if(parentSiteNodeId != null)
                          {
                            cacheInstance.flushGroup("siteNode_" + parentSiteNodeId);
                            cacheInstance.flushGroup("" + parentSiteNodeId);
                            cacheInstance.flushEntry("" + parentSiteNodeId);
                            logger.info("Clearing for:" + parentSiteNodeId);
                          }
                        }
                      }
                      catch (Exception e2)
                      {
                        logger.error("Problem clearing cache for site node version:" + e2.getMessage(), e2);
                    }
                    }
                  }
                  else if(selectiveCacheUpdate && (entity.indexOf("SiteNode") > 0 && entity.indexOf("SiteNodeTypeDefinition") == -1) && useSelectivePageCacheUpdate)
                  {
                    //System.out.println("Entity: " + entity);
                    logger.info("Flushing " + "" + entityId);
                    logger.info("Flushing " + "siteNode_" + entityId);
                    logger.info("Flushing " + "selectiveCacheUpdateNonApplicable");

                    if(cacheName.equals("pageCacheExtra"))
                    {
                      PageCacheHelper.getInstance().notify("siteNode_" + entityId);
                      PageCacheHelper.getInstance().notify("selectiveCacheUpdateNonApplicable");

                      //clearFileCacheForGroup(cacheInstance, "siteNode_" + entityId);
                      //clearFileCacheForGroup(cacheInstance, "selectiveCacheUpdateNonApplicable");
                    }
                    else
                    {
                      cacheInstance.flushEntry("" + entityId);
                      cacheInstance.flushGroup("" + entityId);
                      cacheInstance.flushGroup("siteNode_" + entityId);
                      cacheInstance.flushGroup("selectiveCacheUpdateNonApplicable");
                   
                      if(cacheName.equals("childSiteNodesCache") || cacheName.equals("childPagesCache") || cacheName.equals("siteNodeCache") || cacheName.equals("componentPropertyCacheRepoGroups") || cacheName.equals("componentPropertyVersionIdCacheRepoGroups"))
                      {
                        logger.info("Flushing parent also");
                       
                        String repositoryId = sentRepositoryId;
                        String parentSiteNodeId = sentParentSiteNodeId;
                        try
                        {
                          if(repositoryId == null)
                          {
                            SiteNodeVO snVO = SiteNodeController.getController().getSiteNodeVOWithId(new Integer(entityId));
                            if(snVO != null)
                            {
                              repositoryId = "" + snVO.getRepositoryId();
                              parentSiteNodeId = "" + snVO.getParentSiteNodeId();
                            }
                          }
                          if(cacheName.equals("componentPropertyCacheRepoGroups") || cacheName.equals("componentPropertyVersionIdCacheRepoGroups"))
                          {
                            cacheInstance.flushGroup("" + repositoryId);
                            logger.info("Clearing componentPropertyCacheRepoGroups for repo:" + repositoryId);
                          }

                          if(parentSiteNodeId != null && !parentSiteNodeId.equals(""))
                          {
                            logger.info("Flushing " + "" + entityId);
                            logger.info("Flushing " + "siteNode_" + entityId);

                            cacheInstance.flushGroup("siteNode_" + parentSiteNodeId);
                            cacheInstance.flushGroup("" + parentSiteNodeId);
                            cacheInstance.flushEntry("" + parentSiteNodeId);
                            logger.info("Clearing for:" + parentSiteNodeId);
                          }
                        }
                        catch(SystemException se)
                        {
                          logger.warn("Missing siteNode: " + se.getMessage(), se);
                        }
                      }
                    }

                    logger.info("clearing " + e.getKey() + " with group " + "siteNode_" + entityId);
                }
                  else if(selectiveCacheUpdate && entity.indexOf("ContentVersion") > 0 && useSelectivePageCacheUpdate)
                  {
                    //t.printElapsedTime("CV start....");
                  logger.info("ContentVersion entity was sent: " + entity + ":" + entityId + " and cacheName:" + cacheName);

                    logger.info("Getting eventListeners...");
                      //Object cacheEntryEventListener = eventListeners.get(e.getKey() + "_cacheEntryEventListener");
                    //Object cacheMapAccessEventListener = eventListeners.get(e.getKey() + "_cacheMapAccessEventListener");

                    //System.out.println("entity:" + entity);
                   
                    //System.out.println("Before flushGroup:" +cacheName);
                    logger.info("Before flushGroup...");
                    if(cacheName.equals("pageCacheExtra"))
                    {
                      //clearFileCacheForGroup(cacheInstance, "contentVersion_" + entityId);
                      //clearFileCacheForGroup(cacheInstance, "selectiveCacheUpdateNonApplicable");
                    }
                    else if(cacheName.equals("pageCache"))
                    {
                      logger.info("Skipping clearing pageCache for version");
                      //cacheInstance.flushGroup("contentVersion_" + entityId);
                      //cacheInstance.flushGroup("selectiveCacheUpdateNonApplicable");
                    }
                    else if(cacheName.equals("componentPropertyCacheRepoGroups") || cacheName.equals("componentPropertyVersionIdCacheRepoGroups"))
                    {
                      Timer t2 = new Timer();
                      try
                      {
                        String repositoryId = sentRepositoryId;
                        if(repositoryId == null)
                        {
                          String contentId = sentContentId;
                          if(contentId == null)
                            contentId = "" + ContentVersionController.getContentVersionController().getContentIdForContentVersion(new Integer(entityId));
                          ContentVO contentVO = ContentController.getContentController().getContentVOWithId(new Integer(contentId));
                          repositoryId = "" + contentVO.getRepositoryId();
                        }
                       
                        cacheInstance.flushGroup("" + repositoryId);
                        //t2.printElapsedTime("3");
                        if(cacheName.equals("componentPropertyVersionIdCacheRepoGroups"))
                          cacheInstance.flushGroup("selectiveCacheUpdateNonApplicable");
                        //t2.printElapsedTime("4");
                        logger.info("Clearing componentPropertyCacheRepoGroups for repo:" +repositoryId);
                      }
                      catch (Exception e2)
                      {
                        logger.info("Error loading content with id " + entityId + ":" + e2.getMessage());
                    }
                      //t.printElapsedTime("componentPropertyCacheRepoGroups");
                    }
                    else if(cacheName.equals("assetUrlCacheWithGroups"))
                    {
                      try
                      {
                        String contentId = sentContentId;
                        if(contentId == null || contentId.equals(""))
                          contentId = ""+ContentVersionController.getContentVersionController().getContentIdForContentVersion(new Integer(entityId));
                      cacheInstance.flushGroup("content_" + contentId);
                        logger.info("Clearing assetUrlCacheWithGroups for content:" + "content_" + contentId);
                      }
                      catch (Exception e2)
                      {
                        logger.warn("Flushing assetUrlCacheWithGroups as it was a missing entity - was probably a delete");
                        cacheInstance.flushAll();
                    }
                      //t.printElapsedTime("assetUrlCacheWithGroups");
                    }
                    else if(cacheName.equals("childPagesCache") || cacheName.equals("childSiteNodesCache"))
                    {
                      //System.out.println("childPagesCache:" + entity + "=" + entityId);
                      //t.printElapsedTime("childPagesCache start");
                      try
                      {
                        String contentId = sentContentId;
                        //System.out.println("sentContentId:" + sentContentId);
                        if(contentId == null || contentId.equals(""))
                          contentId = ""+ContentVersionController.getContentVersionController().getContentIdForContentVersion(new Integer(entityId));
                        //System.out.println("contentId:" + contentId);
                        //t.printElapsedTime("childPagesCache A");
                       
                        ContentTypeDefinitionVO metaInfoContentTypeDefinitionVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName("Meta info");
                        //t.printElapsedTime("childPagesCache B");
                        ContentVO contentVO = ContentController.getContentController().getContentVOWithId(new Integer(contentId));
                        //t.printElapsedTime("childPagesCache C");
                       
                        if(metaInfoContentTypeDefinitionVO.getId().equals(contentVO.getContentTypeDefinitionId()))
                        {
                          try
                          {
                            SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithMetaInfoContentId(new Integer(contentId));
                            //t.printElapsedTime("childPagesCache getSiteNodeVOWithMetaInfoContentId");
                            if(siteNodeVO != null)
                            {
                              cacheInstance.flushGroup("siteNode_" + siteNodeVO.getId());
                              cacheInstance.flushGroup("siteNode_" + siteNodeVO.getParentSiteNodeId());
                            }
                          }
                          catch (Exception e2)
                          {
                            logger.error("Did not find a sitenode with this meta info:" + contentId);
                        }
                          cacheInstance.flushGroup("content_" + contentId);
                          cacheInstance.flushGroup("contentVersion_" + entityId);
                          cacheInstance.flushGroup("selectiveCacheUpdateNonApplicable");
                          //t.printElapsedTime("childPagesCache flush done...");
                          logger.info("Clearing childPagesCache for content:" + "content_" + contentId);
                        }
                      }
                      catch (Exception e2)
                      {
                        logger.warn("Flushing childPagesCache as it was a missing entity - was probably a delete");
                        cacheInstance.flushAll();
                    }
                      //t.printElapsedTime("childPagesCache");
                    }
                    else if(cacheName.equals("matchingContentsCache"))
                    {
                      try
                      {
                        String contentId = sentContentId;
                        if(contentId == null || contentId.equals(""))
                          contentId = ""+ContentVersionController.getContentVersionController().getContentIdForContentVersion(new Integer(entityId));

                        try
                        {
                          ContentVO contentVO = ContentController.getContentController().getContentVOWithId(new Integer(contentId));
                          String contentTypeDefinitionId = "" + contentVO.getContentTypeDefinitionId();
                          cacheInstance.flushGroup("selectiveCacheUpdateNonApplicable_contentTypeDefinitionId_" + contentTypeDefinitionId);
                          cacheInstance.putInCache("recacheMark_" + contentTypeDefinitionId, "" + System.currentTimeMillis());
                          cacheInstance.putInCache("recacheMark", "" + System.currentTimeMillis());
                        }
                        catch (Exception e2)
                        {
                          logger.warn("Flushing all as it was a missing entity - was probably a delete:" + e2.getMessage());
                          cacheInstance.flushAll();
                      }
                       
                        cacheInstance.flushGroup("content_" + contentId);
                        logger.info("Clearing assetUrlCacheWithGroups for content:" + "content_" + contentId);
                      }
                      catch (Exception e2)
                      {
                        logger.warn("Flushing all as it was a missing entity - was probably a delete:" + e2.getMessage());
                        cacheInstance.flushAll();
                    }
                      //t.printElapsedTime("matchingContentsCache");
                    }
                    else
                    {
                      //t.printElapsedTime("Before");
                      cacheInstance.flushGroup("contentVersion_" + entityId);
                      //if(!cacheName.equals("contentCache") && !cacheName.equals("contentVersionCache") && !cacheName.equals("contentAttributeCache") && !cacheName.equals("contentVersionIdCache") && !cacheName.equals("contentCategoryCache") && !cacheName.equals("metaInfoContentAttributeCache"))
                        cacheInstance.flushGroup("selectiveCacheUpdateNonApplicable");
                      logger.info("clearing " + e.getKey() + " with selectiveCacheUpdateNonApplicable");
                      //t.printElapsedTime("clearing " + e.getKey() + " with selectiveCacheUpdateNonApplicable");
                    }
                    logger.info("clearing " + e.getKey() + " with group " + "contentVersion_" + entityId);
                 
                    //String[] changedAttributes = new String[]{"Title","NavigationTitle"};
                   
                    try
                    {
                      //t.printElapsedTime("Cache 3.4");
                      logger.info("Before contentVersionVO...");
                      //System.out.println("cacheName:" + cacheName);
                      //System.out.println("entity:" + entity);
                      //System.out.println("entityId:" + entityId);
                     
                      String contentIdString = sentContentId;
                      String contentTypeDefinitionId = sentContentTypeDefinitionId;
                      String contentIsProtected = sentContentIsProtected;
                      if(contentIdString == null || contentIdString.equals(""))
                      {
                        try
                        {
                          contentIdString = "" + ContentVersionController.getContentVersionController().getContentIdForContentVersion(new Integer(entityId));
                        }
                        catch (Exception e2)
                        {
                          logger.info("Error loading content with id " + entityId + ":" + e2.getMessage());
                      }
                      }

                      Integer contentId = null;
                      if(contentIdString != null)
                        contentId = new Integer(contentIdString);
                     
                      if(contentTypeDefinitionId == null && contentIsProtected == null && contentId != null)
                      {
                        ContentVO contentVO = ContentController.getContentController().getContentVOWithId(new Integer(contentId));
                        contentTypeDefinitionId = ""+contentVO.getContentTypeDefinitionId();
                        contentIsProtected = ""+contentVO.getIsProtected().intValue();
                      }
                     
                      //t.printElapsedTime("Cache 3.5");
                      //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Cache 3.5", t.getElapsedTime());

                    if(contentId != null)
                      {
                        List<String> changes = Collections.EMPTY_LIST;
                        //System.out.println("extraInformation:" + extraInformation);
                        String changedAttributes = extraInformation == null ? null : extraInformation.get("changedAttributeNames");
                        if(changedAttributes != null && changedAttributes.length() > 0)
                          changes = new ArrayList<String>(Arrays.asList(StringUtils.split(changedAttributes, ",")));


                        //ContentVO contentVO = ContentController.getContentController().getContentVOWithId(new Integer(contentId));

                        logger.info("Before flushGroup2...");
                        if(cacheName.equals("pageCacheExtra"))
                        {
                          if(contentIsProtected.equals(""+ContentVO.YES.intValue()))
                          {
                            List<InterceptionPointVO> interceptionPointVOList = InterceptionPointController.getController().getInterceptionPointVOList("Content");
                            for(InterceptionPointVO interceptionPointVO : interceptionPointVOList)
                            {
                              if(interceptionPointVO.getName().endsWith(".Read"))
                              {
                                String acKey = "" + interceptionPointVO.getId() + "_" + entityId;
                                CacheController.clearUserAccessCache(acKey);                     
                              }
                            }
                          }
                         
                          PageCacheHelper.getInstance().notify("selectiveCacheUpdateNonApplicable_contentTypeDefinitionId_" + contentTypeDefinitionId);
                          PageCacheHelper.getInstance().notify("content_" + contentId);
                          //clearFileCacheForGroup(cacheInstance, "selectiveCacheUpdateNonApplicable_contentTypeDefinitionId_" + contentVO.getContentTypeDefinitionId());
                         
                          if((changes == null || changes.size() == 0) && CmsPropertyHandler.getOperatingMode().equals("3"))
                          {
                            ContentVersionVO oldContentVersionVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId(new Integer(entityId));
                            ContentVersionVO newContentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentId, oldContentVersionVO.getLanguageId(), new Integer(CmsPropertyHandler.getOperatingMode()));
                            if(newContentVersionVO != null && oldContentVersionVO != null && newContentVersionVO.getId().equals(oldContentVersionVO.getId()))
                            {
                              oldContentVersionVO = null;
                              //System.out.println("SHIT - same version allready - must find other");
                              List<SmallestContentVersionVO> contentVersionVOList = ContentVersionController.getContentVersionController().getSmallestContentVersionVOList(new Integer(contentId));
                              for(SmallestContentVersionVO cvVO : contentVersionVOList)
                              {
                                if(!cvVO.getId().equals(newContentVersionVO.getId()) && cvVO.getStateId().equals(new Integer(CmsPropertyHandler.getOperatingMode())) && cvVO.getLanguageId().equals(newContentVersionVO.getLanguageId()) && cvVO.getIsActive() && (oldContentVersionVO == null || oldContentVersionVO.getId() < cvVO.getId()))
                                {
                                  oldContentVersionVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId(cvVO.getId());
                                }
                              }
                            }
                           
                            //System.out.println("Now we should have current and previous version:" + newContentVersionVO + " / " + oldContentVersionVO);
                            if(newContentVersionVO != null && oldContentVersionVO != null)
                              changes = ContentVersionController.getContentVersionController().getChangedAttributeNames(newContentVersionVO, oldContentVersionVO);
                          }

                          //System.out.println("changes:" + changes);
                          for(String changedAttributeName : changes)
                          {
                            if(changedAttributeName.indexOf("ComponentStructure") > -1)
                            {
                              //Map allreadyFlushedEntries....
                              Set<String> groupEntries = (Set<String>)cacheInstance.getCache().cacheMap.getGroup("content_" + contentId + "_ComponentStructureDependency");
                              //System.out.println("groupEntries:" + groupEntries);
                              if(groupEntries != null)
                              {
                                System.out.println("groupEntries:" + groupEntries.size());
                                outer:for(String key : groupEntries)
                                {
                                  //System.out.println("key 1:" + key);
                                  try
                                  {
                                    //String[] usedEntities = (String[])cacheInstance.getFromCache(key + "_entities");
                                    byte[] usedEntitiesByteArray = (byte[])cacheInstance.getFromCache(key + "_entitiesAsByte");
                                    String usedEntitiesString = compressionHelper.decompress(usedEntitiesByteArray);
                                    //t.printElapsedTime("Decompress to " + usedEntitiesString.length() + " took");
                                    String[] usedEntities = StringUtils.split(usedEntitiesString, "|");
                                    //t.printElapsedTime("Split to usedEntities " + usedEntities.length + " took");
                                   
                                    ContentVersionVO newContentVersionVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId(new Integer(entityId));
                                    String newComponentStructure = ContentVersionController.getContentVersionController().getAttributeValue(newContentVersionVO, "ComponentStructure", false);
   
                                    for(String usedEntity : usedEntities)
                                    {
                                      //System.out.println("usedEntity:" + usedEntity);
                                      if(usedEntity.startsWith("content_" + contentId + "_ComponentStructure("))
                                      {
                                        //System.out.println("Match - now lets parse: " + usedEntity);
                                        String arguments = usedEntity.substring(usedEntity.indexOf("(") + 1, usedEntity.indexOf(")"));
                                        Integer oldComponentPropertyHash = new Integer(usedEntity.substring(usedEntity.indexOf("=") + 1));
                                        String[] args = arguments.split(",");
                                        Integer componentId = new Integer(args[0]);
                                        String propertyName = args[1];
                                        Integer siteNodeId = new Integer(args[2]);
                                        Integer languageId = new Integer(args[3]);
                                        //System.out.println("componentId:" + componentId);
                                        //System.out.println("propertyName:" + propertyName);
                                        //System.out.println("siteNodeId:" + siteNodeId);
                                        //System.out.println("languageId:" + languageId);
                                     
                                        int newComponentPropertyHash = getPropertyAsStringHashCode(newComponentStructure, componentId, propertyName, siteNodeId, languageId);
                                        //System.out.println("oldComponentPropertyHash:" + oldComponentPropertyHash);
                                        //System.out.println("newComponentPropertyHash:" + newComponentPropertyHash);
                                        if(oldComponentPropertyHash.intValue() != newComponentPropertyHash)
                                        {
                                          //System.out.println("Yes - clearing - must have changed something important:" + usedEntity);
                                          PageCacheHelper.getInstance().notify(usedEntity);
                                          //clearFileCacheForGroup(cacheInstance, usedEntity);
                                        }
                                        else
                                        {
                                          //System.out.println("Flushing content_" + currentPageMetaInfoContentId + "_ComponentStructure just to catch page itself");
                                          //cacheInstance.flushGroup("content_" + currentPageMetaInfoContentId + "_ComponentStructure");
                                          //System.out.println("Flushing content_" + contentId + "_ComponentStructure just to catch page itself");
                                          //cacheInstance.flushGroup("content_" + contentId + "_ComponentStructure");
                                        }
                                       
                                      }
                                      else if(usedEntity.startsWith("content_" + contentId + "_ComponentStructure:"))
                                      {
                                        //System.out.println("Match - now lets parse component order etc: " + usedEntity);
                                        String xPath = usedEntity.substring(usedEntity.indexOf(":") + 1, usedEntity.lastIndexOf("="));
                                        Integer oldComponentPropertyHash = new Integer(usedEntity.substring(usedEntity.lastIndexOf("=") + 1));
                                        //System.out.println("xPath:" + xPath);
                                       
                                        int newComponentPropertyHash = getComponentsAsStringHashCode(newComponentStructure, xPath);
                                        //System.out.println("oldComponentPropertyHash:" + oldComponentPropertyHash);
                                        //System.out.println("newComponentPropertyHash:" + newComponentPropertyHash);
                                        if(oldComponentPropertyHash.intValue() != newComponentPropertyHash)
                                        {
                                          //System.out.println("Yes - clearing - must have changed order or added/subtracted components:" + usedEntity);
                                          PageCacheHelper.getInstance().notify(usedEntity);
                                          //clearFileCacheForGroup(cacheInstance, usedEntity);
                                        }
                                      }
                                    }
                                  }
                                  catch (Exception ex)
                                  {
                                  //logger.error("Got error trying to update cache:" + ex.getMessage());
                                    logger.warn("Got error trying to update cache:" + ex.getMessage(), ex);

                                    //clearFileCacheForGroup(cacheInstance, "content_" + contentId + "_" + changedAttributeName);
                                    //cacheInstance.flushGroup("content_" + contentId + "_" + changedAttributeName);
                                    //logger.warn("Cleared pageCache for " + "content_" + contentId + "_" + changedAttributeName);

                                    break outer;
                                  }
                                }
                              }
                            }
                            else
                            {
                              PageCacheHelper.getInstance().notify("content_" + contentId + "_" + changedAttributeName);
                              //clearFileCacheForGroup(cacheInstance, "content_" + contentId + "_" + changedAttributeName);
                              //System.out.println("Cleared for " + "content_" + contentId + "_" + changedAttributeName);
                            }
                          } 

                          //t.printElapsedTime("Handled page cache extra");
                          RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Handled page cache extra", t.getElapsedTime())
                          //clearFileCacheForGroup(cacheInstance, "content_" + contentId);
                        }
                        else if(cacheName.equals("pageCache"))
                        {
                          //t.printElapsedTime("Page cache start");
                          RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Page cache start", t.getElapsedTime());
                          logger.info("Flushing pageCache for content type def");

                          String contentTypeDefKey = "selectiveCacheUpdateNonApplicable_contentTypeDefinitionId_" + contentTypeDefinitionId;
                          cacheInstance.flushGroup(contentTypeDefKey);
                          //cacheInstance.flushGroup("selectiveCacheUpdateNonApplicable_contentTypeDefinitionId_" + contentVO.getContentTypeDefinitionId());
                          //cacheInstance.flushGroup("content_" + contentVO.getId());
                          //System.out.println("Flushing:" + getPooledString(1, contentVO.getId()));
                          cacheInstance.flushGroup(getPooledString(1, new Integer(contentId)));
                          PageCacheHelper.getInstance().notify("content_" + contentId);

                          ContentVersionVO oldContentVersionVO = null;
                          ContentVersionVO newContentVersionVO = null;
                         
                          String debug = "";
                          if((changes == null || changes.size() == 0) && CmsPropertyHandler.getOperatingMode().equals("3"))
                          {
                            debug += "entityId:" + entityId + "\n";
                            debug += "contentId:" + contentId + "\n";
                            oldContentVersionVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId(new Integer(entityId));
                            debug += "oldContentVersionVO:" + oldContentVersionVO.getId() + ":" + oldContentVersionVO.getLanguageId() + "\n";
                            debug += "oldContentVersionVO:" + CmsPropertyHandler.getOperatingMode() + "\n";
                            newContentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentId, oldContentVersionVO.getLanguageId(), new Integer(CmsPropertyHandler.getOperatingMode()));
                            debug += "newContentVersionVO:" + newContentVersionVO + "\n";
                            if(newContentVersionVO != null && oldContentVersionVO != null && newContentVersionVO.getId().equals(oldContentVersionVO.getId()))
                            {
                              debug += "newContentVersionVO:" + newContentVersionVO.getId() + "\n";
                              oldContentVersionVO = null;
                              debug += "SHIT - same version allready - must find other";
                              List<SmallestContentVersionVO> contentVersionVOList = ContentVersionController.getContentVersionController().getSmallestContentVersionVOList(new Integer(contentId));
                              for(SmallestContentVersionVO cvVO : contentVersionVOList)
                              {
                                if(!cvVO.getId().equals(newContentVersionVO.getId()) && cvVO.getStateId().equals(new Integer(CmsPropertyHandler.getOperatingMode())) && cvVO.getLanguageId().equals(newContentVersionVO.getLanguageId()) && cvVO.getIsActive() && (oldContentVersionVO == null || oldContentVersionVO.getId() < cvVO.getId()))
                                {
                                  oldContentVersionVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId(cvVO.getId());
                                }
                              }
                              debug += "oldContentVersionVO:" + (oldContentVersionVO == null ? "null" : oldContentVersionVO.getId()) + "\n";
                            }
                           
                            //System.out.println("Now we should have current and previous version:" + newContentVersionVO + " / " + oldContentVersionVO);
                            if(newContentVersionVO != null && oldContentVersionVO != null)
                              changes = ContentVersionController.getContentVersionController().getChangedAttributeNames(newContentVersionVO, oldContentVersionVO);
                          }

                          //t.printElapsedTime("Changes analyzed");
                        //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Changes analyzed", t.getElapsedTime());

                          if((changes == null || changes.size() == 0&& CmsPropertyHandler.getOperatingMode().equals("3"))
                          {
                            if(oldContentVersionVO == null || newContentVersionVO == null)
                            {
                              //Hur kan det bli detta????
                              logger.warn("Fishy 1: " + oldContentVersionVO + ":" + newContentVersionVO + " in " + CmsPropertyHandler.getContextRootPath());
                              logger.warn("DEBUG: " + debug);
                            }
                            else
                            {
                              logger.warn("Fishy 2: No changes found between content versions " + newContentVersionVO.getId() + " and " + oldContentVersionVO.getId() + " in " + CmsPropertyHandler.getContextRootPath());
                              logger.warn("DEBUG: " + debug);
                              logger.warn("Fishy: newContentVersionVO: " + newContentVersionVO.getVersionValue());
                              logger.warn("Fishy: newContentVersionVO: " + oldContentVersionVO.getVersionValue());
                            }
                            logger.warn("Just to make sure pages are updated we pretend all attributes changed until we find the bug");
                            changes = ContentVersionController.getContentVersionController().getAttributeNames(newContentVersionVO);
                          }
                         
                          //System.out.println("changes:" + changes);
                          for(String changedAttributeName : changes)
                          {
                            logger.warn("changedAttributeName: " + changedAttributeName);
                            if(changedAttributeName.indexOf("ComponentStructure") > -1 && cacheName.equals("pageCache"))
                            {
                              //Map allreadyFlushedEntries....
                              //It's something wrong here..
                              GeneralCacheAdministrator pageCacheExtraInstance = (GeneralCacheAdministrator)caches.get("pageCacheExtra");
                              String cacheGroupKey = "content_" + contentId + "_ComponentStructureDependency";
                              //Set<String> groupEntries = (Set<String>)cacheInstance.getCache().cacheMap.getGroup("content_" + contentId + "_ComponentStructureDependency");
                              Set<String> groupEntries = (Set<String>)cacheInstance.getCache().cacheMap.getGroup(getPooledString(cacheGroupKey.hashCode()));
                              //System.out.println("groupEntries:" + groupEntries);
                              if(groupEntries != null)
                              {
                                outer:for(String key : groupEntries)
                                {
                                logger.info("key 2:" + key);
                                try
                                {
                                  //String[] usedEntities = (String[])pageCacheExtraInstance.getFromCache(key + "_entities");
                                    byte[] usedEntitiesByteArray = (byte[])pageCacheExtraInstance.getFromCache(key + "_entitiesAsByte");
                                    String usedEntitiesString = compressionHelper.decompress(usedEntitiesByteArray);
                                    //t.printElapsedTime("Decompress to " + usedEntitiesString.length() + " took");
                                    String[] usedEntities = StringUtils.split(usedEntitiesString, ",");
                                    //t.printElapsedTime("Split to usedEntities " + usedEntities.length + " took");
                                 
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.