Examples of DotCacheAdministrator


Examples of com.dotmarketing.business.DotCacheAdministrator

     * This method removes the given virtual link path from the cache
     * and also sends an invalidation
     * @param url
     */
    public static void removePathFromCache(String url) {
      DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();
      Logger.debug(VirtualLinksCache.class, "removePathFromCache: url = " + url);
      cache.remove(sanitizeKey(url),getPrimaryGroup());
    }
View Full Code Here

Examples of com.dotmarketing.business.DotCacheAdministrator

      Logger.debug(VirtualLinksCache.class, "removePathFromCache: url = " + url);
      cache.remove(sanitizeKey(url),getPrimaryGroup());
    }
   
    public static void mapAllVirtualLinks() {
      DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();
      List<VirtualLink> vls = VirtualLinkFactory.getVirtualLinks();
        Iterator<VirtualLink> iter = vls.iterator();
        Logger.debug(VirtualLinksCache.class, " mapping " + vls.size() + " virtual link(s) ");
        while (iter.hasNext()) {
            VirtualLink vl = (VirtualLink) iter.next();
            if (vl != null && InodeUtils.isSet(vl.getInode()))
            {
              Logger.debug(VirtualLinksCache.class, "mapping: " + vl.getUrl() + " -> " + vl.getUri());
                cache.put(sanitizeKey(vl.getUrl()), vl.getUri(), getPrimaryGroup());
            }
        }
    }  
View Full Code Here

Examples of com.dotmarketing.business.DotCacheAdministrator

            }
        }
    }  

    public static void clearCache(){
    DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();
      //clear the cache
      cache.flushGroup(getPrimaryGroup());
  }
View Full Code Here

Examples of com.dotmarketing.business.DotCacheAdministrator

  public void addFolder(Folder f, Identifier id) {

    if(f ==null || id ==null || ! UtilMethods.isSet(id.getId()) || ! UtilMethods.isSet(id.getPath())){
      return;
    }
    DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();
   
    // Folder by Inode
    String inode = f.getInode();
    cache.put(getPrimaryGroup() + inode, f, getPrimaryGroup());

    // Folder by Path
    String folderPath = f.getHostId() + ":" + cleanPath(id.getPath()) ;
    cache.put(getPrimaryGroup() + folderPath, f, getPrimaryGroup());

  }
View Full Code Here

Examples of com.dotmarketing.business.DotCacheAdministrator

    cache.put(getPrimaryGroup() + folderPath, f, getPrimaryGroup());

  }
  // Folder by Inode
  public Folder getFolder(String inode) {
    DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();
    Folder f = null;
    try {
      f = (Folder) cache.get(getPrimaryGroup() + inode, getPrimaryGroup());
    } catch (DotCacheException e) {
      Logger.debug(FolderCache.class, "Cache Entry not found", e);
    }

    return f;
View Full Code Here

Examples of com.dotmarketing.business.DotCacheAdministrator

  // Folder by Path
  public Folder getFolderByPathAndHost(String path, Host host) {

    if(host==null) return null;

    DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();
    String folderPath = host.getIdentifier() + ":" + cleanPath(path) ;
    Folder f = null;
    try {
      f = (Folder) cache.get(getPrimaryGroup() + folderPath, getPrimaryGroup());
    } catch (DotCacheException e) {
      Logger.debug(FolderCache.class, "Cache Entry not found", e);
    }

View Full Code Here

Examples of com.dotmarketing.business.DotCacheAdministrator

    return f;
  }

  public void removeFolder(Folder f, Identifier id) {

    DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();
    String inode = f.getInode();
   
    // Folder by Inode
    cache.remove(getPrimaryGroup() + inode, getPrimaryGroup());
   
    try{
      // Folder by Path
      String folderPath = f.getHostId() + ":" + cleanPath(id.getPath()) ;
      cache.remove(getPrimaryGroup() + folderPath, getPrimaryGroup());
    }
    catch(NullPointerException npe){
      Logger.debug(FolderCache.class, "Cache Entry not found", npe);
    }
  }
View Full Code Here

Examples of com.dotmarketing.business.DotCacheAdministrator

     */
    public static String addToLiveAssetToCache ( Versionable asset, Long languageId ) {

        HostAPI hostAPI = APILocator.getHostAPI();

      DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();
        //The default value for velocity page extension
        String ext = Config.getStringProperty("VELOCITY_PAGE_EXTENSION");
    // we use the identifier uri for our mappings.
        String ret = null;
        try{
          Identifier id = APILocator.getIdentifierAPI().find(asset);
          //Obtain the host of the webassets
          User systemUser = APILocator.getUserAPI().getSystemUser();
        Host host = hostAPI.findParentHost((Treeable)asset, systemUser, false);
        if(host == null) ret = null;

        //Obtain the URI for future uses
        String uri = id.getURI();
        //Obtain the inode value of the host;
        String hostId = host.getIdentifier();

        //if this is an index page, map its directories to it
        if (UtilMethods.isSet(uri))
        {
          if(uri.endsWith("." + ext))
          {
            Logger.debug(LiveCache.class, "Mapping: " + uri + " to " + uri);

            //Add the entry to the cache
          cache.put(getPrimaryGroup() + hostId + ":" + uri,uri, getPrimaryGroup() + "_" + hostId);

          if(uri.endsWith("/index." + ext))
          {
              //Add the entry to the cache
              Logger.debug(LiveCache.class, "Mapping: " + uri.substring(0,uri.lastIndexOf("/index." + ext)) + " to " + uri);
            cache.put(getPrimaryGroup() + hostId + ":" + uri.substring(0,uri.lastIndexOf("/index." + ext)),uri, getPrimaryGroup() + "_" + hostId);
            //Add the entry to the cache
              Logger.debug(LiveCache.class, "Mapping: " + uri.substring(0,uri.lastIndexOf("/index." + ext)) + " to " + uri);
            cache.put(getPrimaryGroup() + hostId + ":" + uri.substring(0,uri.lastIndexOf("index." + ext)),uri, getPrimaryGroup() + "_" + hostId);
          }
        ret = uri;
        }
        else if (asset instanceof Link) {
          Folder parent = (Folder) APILocator.getFolderAPI().findParentFolder((Link)asset, APILocator.getUserAPI().getSystemUser(), false);
          String path = ((Link)asset).getURI(parent);
          //add the entry to the cache
            Logger.debug(LiveCache.class, "Mapping: " + uri + " to " + path);
          cache.put(getPrimaryGroup() + hostId + ":" + uri,path, getPrimaryGroup() + "_" + hostId);
          ret = path;
            } else if ( asset instanceof Contentlet ) {
                String path = APILocator.getFileAssetAPI().getRelativeAssetPath( APILocator.getFileAssetAPI().fromContentlet( (Contentlet) asset ) );
                //add the entry to the cache
                Logger.debug( LiveCache.class, "Mapping: " + uri + " to " + path );

                //For contentlet lets use the language to build the key for the cache
                cache.put( getPrimaryGroup() + hostId + ":" + uri, path, getPrimaryGroup() + "_" + hostId + "_" + languageId );
                ret = path;

            }else {
          String path = APILocator.getFileAPI().getRelativeAssetPath((Inode)asset);
          //add the entry to the cache
            Logger.debug(LiveCache.class, "Mapping: " + uri + " to " + path);
          cache.put(getPrimaryGroup() + hostId + ":" + uri,path, getPrimaryGroup() + "_" + hostId);
          ret = path;
        }
        }
        } catch (DotDataException e) {
          Logger.error(LiveCache.class,"Unable to retrieve identifier", e);
View Full Code Here

Examples of com.dotmarketing.business.DotCacheAdministrator

     * @throws DotDataException
     * @throws DotStateException
     */
  public static String getPathFromCache(String URI, String hostId, Long languageId) throws DotStateException, DotDataException, DotSecurityException{

    DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();

        if ( languageId == null ) {
            languageId = APILocator.getLanguageAPI().getDefaultLanguage().getId();
        }

    String _uri = null;
        try {
            //First lets search in cache for a specific language
            _uri = (String) cache.get( getPrimaryGroup() + hostId + ":" + URI, getPrimaryGroup() + "_" + hostId + "_" + languageId );
            //If nothing found try without a language
            if ( _uri == null ) {
                _uri = (String) cache.get( getPrimaryGroup() + hostId + ":" + URI, getPrimaryGroup() + "_" + hostId );
            }
        } catch ( DotCacheException e ) {
            Logger.debug( LiveCache.class, "Cache Entry not found", e );
        }

    if(_uri != null)
    {
      if(_uri.equals(WebKeys.Cache.CACHE_NOT_FOUND))
        return null;
        return _uri;
    }

    String ext = Config.getStringProperty("VELOCITY_PAGE_EXTENSION");
    if (URI.endsWith("/")) {
      //it's a folder path, so I add index.{pages ext} at the end
      URI += "index." + ext;

      // try again with an index page this time
      try{
        _uri = (String) cache.get(getPrimaryGroup() + hostId + ":" + URI,getPrimaryGroup() + "_" + hostId);
      }catch (DotCacheException e) {
        Logger.debug(LiveCache.class,"Cache Entry not found", e);
        }

      if(_uri != null)
      {
        if(_uri.equals(WebKeys.Cache.CACHE_NOT_FOUND))
          return null;
          return _uri;
      }
    }


    // lets try to lazy get it.
    Host fake = new Host();
    fake.setIdentifier(hostId);
    Identifier id = APILocator.getIdentifierAPI().find( fake,URI);

    if(!InodeUtils.isSet(id.getInode()))
    {
      cache.put(getPrimaryGroup() + hostId + ":" + URI, WebKeys.Cache.CACHE_NOT_FOUND, getPrimaryGroup() + "_" + hostId);

      //it's a folder path, so I add index.html at the end
      URI += "/index." + ext;
      id = APILocator.getIdentifierAPI().find( fake, URI);
      if(!InodeUtils.isSet(id.getInode()))
      {
        cache.put(getPrimaryGroup() + hostId + ":" + URI, WebKeys.Cache.CACHE_NOT_FOUND, getPrimaryGroup() + "_" + hostId);
          return null;
      }
    }

    Versionable asset;
    if(id.getAssetType().equals("contentlet")){

            User systemUser = APILocator.getUserAPI().getSystemUser();
            try {
                asset = APILocator.getContentletAPI().findContentletByIdentifier( id.getId(), true, languageId, systemUser, false );
            } catch ( DotContentletStateException e ) {

                Logger.debug( LiveCache.class, e.getMessage() );

                //If we did not find the asset with for given language lets try with the default language
                if ( !languageId.equals( APILocator.getLanguageAPI().getDefaultLanguage().getId() ) ) {
                    languageId = APILocator.getLanguageAPI().getDefaultLanguage().getId();
                    asset = APILocator.getContentletAPI().findContentletByIdentifier( id.getId(), true, languageId, systemUser, false );
                } else {
                    throw e;
                }
            }

        } else {
      asset =  APILocator.getVersionableAPI().findLiveVersion(id, APILocator.getUserAPI().getSystemUser(), false);
    }

    if(asset!=null && InodeUtils.isSet(asset.getInode()))
    {
        Logger.debug(PublishFactory.class, "Lazy Mapping: " + id.getURI() + " to " + URI);
        //The cluster entry doesn't need to be invalidated when loading the entry lazily,
        //if the entry gets invalidated from the cluster in this case causes an invalidation infinite loop
            return addToLiveAssetToCache( asset, languageId );
        } else {
      //Identifier exists but the asset is not live
      cache.put(getPrimaryGroup() + hostId + ":" + URI, WebKeys.Cache.CACHE_NOT_FOUND, getPrimaryGroup() + "_" + hostId);
        return null;
    }

  }
View Full Code Here

Examples of com.dotmarketing.business.DotCacheAdministrator

*
*/
public class WorkingCache {
   
    public static String addToWorkingAssetToCache(Versionable asset) throws DotIdentifierStateException, DotDataException{
      DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();
    // we use the identifier uri for our mappings.
    Identifier id = APILocator.getIdentifierAPI().find(asset);
    //Velocity Page Extension
    String ext = Config.getStringProperty("VELOCITY_PAGE_EXTENSION");
    //Obtain the URI
    String uri = id.getURI();    
    //Obtain the INODE
    String hostId = id.getHostId();
    String ret = null;
    if (UtilMethods.isSet(uri))
    {       
      Logger.debug(WorkingCache.class, "Mapping Working: " + uri + " to " + uri);
      if(uri.endsWith("." + ext))
      {
          //add it to the cache
        //for now we are adding the page URI
        cache.put(getPrimaryGroup() + hostId + "-" + uri,uri, getPrimaryGroup() + "_" + hostId);

        //if this is an index page, map its directories to it
        if(id.getURI().endsWith("/index." + ext))
        {
          Logger.debug(WorkingCache.class, "Mapping Working: " + uri.substring(0,uri.lastIndexOf("/index." + ext)) + " to " + uri);
          cache.put(getPrimaryGroup() + hostId + "-" + uri.substring(0,uri.lastIndexOf("/index." + ext)),uri, getPrimaryGroup() + "_" + hostId);
          Logger.debug(WorkingCache.class, "Mapping Working: " + id.getURI().substring(0,id.getURI().lastIndexOf("index." + ext)) + " to " + uri);
          cache.put(getPrimaryGroup() + hostId + "-" + uri.substring(0,uri.lastIndexOf("index." + ext)), uri, getPrimaryGroup() + "_" + hostId);
        }
        ret = uri;
      }
      else if (asset instanceof Link) {
        Folder parent;
        try {
          parent = (Folder) APILocator.getFolderAPI().findParentFolder((Link)asset, APILocator.getUserAPI().getSystemUser(), false);
          String path = ((Link)asset).getURI(parent);
          //add the entry to the cache
          Logger.debug(WorkingCache.class, "Mapping: " + uri + " to " + path);
          cache.put(getPrimaryGroup() + hostId + "-" + uri,path, getPrimaryGroup() + "_" + hostId);
          ret = path;
        } catch (DotSecurityException e) {
          Logger.error(WorkingCache.class, "Unable to get Folder for Link", e);
        }
      }else if(asset instanceof com.dotmarketing.portlets.contentlet.model.Contentlet){
        String path = APILocator.getFileAssetAPI().getRelativeAssetPath(APILocator.getFileAssetAPI().fromContentlet((com.dotmarketing.portlets.contentlet.model.Contentlet)asset));
        //add the entry to the cache
        Logger.debug(WorkingCache.class, "Mapping: " + uri + " to " + path);
        cache.put(getPrimaryGroup() + hostId + "-" + uri,path, getPrimaryGroup() + "_" + hostId);
        ret = path;
      }else {
        String path = APILocator.getFileAPI().getRelativeAssetPath((Inode)asset);
        //add the entry to the cache
        Logger.debug(WorkingCache.class, "Mapping: " + uri + " to " + path);
        cache.put(getPrimaryGroup() + hostId + "-" + uri,path, getPrimaryGroup() + "_" + hostId);
        ret = path;
     


    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.