Exemplo n.º 1
0
  public static void putPocessTiming(
      String projectId, String userId, String domainId, ParamType paramType) {
    // get cache
    try {
      Cache cache = CacheUtil.getCache();
      Node rootNode = cache.getRoot();
      String roleTree = domainId + "/" + projectId + "/" + userId + "/" + PM_ENABLE_PROCESS_TIMING;
      rootNode.put(roleTree, paramType.getValue());

    } catch (MalformedObjectNameException e) {
      e.printStackTrace();
    } catch (NullPointerException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  public static String clearPocessTiming(String projectId, String userId, String domainId) {
    String processTimingPMFlag = "NONE";
    // get cache
    try {

      Node rootNode = CacheUtil.getCache().getRoot();
      processTimingPMFlag =
          (String)
              rootNode.put(
                  domainId + "/" + projectId + "/" + userId + "/" + PM_ENABLE_PROCESS_TIMING, null);
    } catch (MalformedObjectNameException e) {
      e.printStackTrace();
    } catch (NullPointerException e) {
      e.printStackTrace();
    }
    return processTimingPMFlag;
  }
Exemplo n.º 3
0
  public void cacheContentObject(
      String contentObjectId, Object contentObject, CacheRegion cacheRegion, String cacheKey)
      throws Exception {
    try {

      if (enabled
          && StringUtils.isNotBlank(contentObjectId)
          && contentObject != null
          && CacheRegion.NONE != cacheRegion) {

        Cache cache = cmsRepositoryCache.getCache();

        Node rootNode = cache.getRoot();

        if (cacheKey == null) {
          cacheKey = contentObjectId;
        }

        Fqn<String> contentObjectIdFQN = constructJcrQueryFQN(contentObjectId, cacheRegion);

        if (!rootNode.hasChild(contentObjectIdFQN)) {

          logger.debug(
              "The following content object cache node does not exist and will be added in Query Cache. The content object cache node to be cached is {} under key {}",
              contentObjectIdFQN,
              cacheKey);

          // Put query results to cache
          cache.put(contentObjectIdFQN, cacheKey, contentObject);

        } else {
          // Content Object already exists
          Node contentOjectCacheNode = rootNode.getChild(contentObjectIdFQN);

          // Write results only if there is no matching rowRangeAndRenderProperties query
          if (contentOjectCacheNode.get(cacheKey) == null) {

            if (contentObject != null) {
              logger.debug(
                  "The following content object cache node exists in Query Cache. The existing Jcr Query node is {} . The key is {} and content object is not null. So a map entry with this key and the content object will be created",
                  contentObjectIdFQN,
                  cacheKey);

              contentOjectCacheNode.put(cacheKey, contentObject);
            } else {
              // Remove Content Object Cache Node
              // cache.remove(jcrQueryFQN);
              logger.debug(
                  "The following content object cache node exists in Query Cache. The existing Jcr Query node is {}.The key is {}.The content objec IS NULL. So NO map entry with this key and the content object will be created",
                  contentObjectIdFQN,
                  cacheKey);
            }
          } else {
            logger.debug(
                "The following content object cache node exists in Query Cache. The existing Jcr Query node is {}. The key is {}. So NO map entry with this key and the content object need to be created",
                contentObjectIdFQN,
                cacheKey);
          }
        }
      }
    } catch (Exception e) {
      if (propagateExceptions) throw e;
      else logger.error("Exception in cache ", e);
    }
  }
Exemplo n.º 4
0
  public void cacheJcrQueryResults(
      CmsCriteria cmsCriteria,
      Object outcome,
      RenderProperties renderProperties,
      String cacheKeyPrefix)
      throws Exception {
    // Cache only if a query is provided and outcome is not null
    try {
      String jcrQuery = cmsCriteria.getXPathQuery();

      if (enabled && !StringUtils.isBlank(jcrQuery)) {

        if (!cmsCriteria.isCacheable()) {
          logger.debug("Jcr query {} is not cacheable. Query will not be cached.", jcrQuery);
          return;
        }

        Cache cache = cmsRepositoryCache.getCache();

        Node rootNode = cache.getRoot();

        String cacheKey =
            constructCacheKey(
                cacheKeyPrefix, cmsCriteria.getOffset(), cmsCriteria.getLimit(), renderProperties);

        Fqn<String> jcrQueryFQN = constructJcrQueryFQN(jcrQuery, cmsCriteria.getCacheRegion());

        if (!rootNode.hasChild(jcrQueryFQN)) {
          if (outcome != null) {
            logger.debug(
                "The following jcr query node does not exist and will be added in Query Cache along with the row range and render properties key (not null query results). The Jcr Query node to be cached is {} and the cache key is ",
                jcrQueryFQN,
                cacheKey);

            // Put query results to cache
            cache.put(jcrQueryFQN, cacheKey, outcome);

          } else {
            logger.debug(
                "The following jcr query node does not exist in Query Cache but WILL NOT CACHED because query result is null. The Jcr Query node is {} and the cache key is {}",
                jcrQueryFQN,
                cacheKey);
          }
        } else {
          // JcrQuery already exists
          Node jcrQueryNode = rootNode.getChild(jcrQueryFQN);

          // Write results only if there is no matching rowRangeAndRenderProperties query
          if (jcrQueryNode.get(cacheKey) == null) {

            if (outcome != null) {
              logger.debug(
                  "The following jcr query node exists in Query Cache. The existing Jcr Query node is {}. The row range and properties key does not exist in cache. The key is {}. The query outcome is not null. So a map entry with this key and the query results will be created",
                  jcrQueryFQN,
                  cacheKey);
              jcrQueryNode.put(cacheKey, outcome);
            } else {
              // Remove jcrQueryFqn
              // cache.remove(jcrQueryFQN);
              logger.debug(
                  "The following jcr query node exists in Query Cache. The existing Jcr Query node is {}. The row range and properties key does not exist in cache. The key is {} . The query outcome IS NULL. So NO map entry with this key and the query results will be created",
                  jcrQueryFQN,
                  cacheKey);
            }
          } else {
            logger.debug(
                "The following jcr query node exists in Query Cache. The existing Jcr Query node is {}. The cache key {} does also exist in cache. So NO map entry with this key and the query results need to be created",
                jcrQueryFQN,
                cacheKey);
          }
        }
      }
    } catch (Exception e) {
      if (propagateExceptions) throw e;
      else logger.error("Exception in cache ", e);
    }
  }