Package Torello.Java

Class HiLiteMe.Cache

  • Enclosing class:
    HiLiteMe

    public static class HiLiteMe.Cache
    extends java.lang.Object
    HiLiteMe Cache - Documentation.

    If using the HiLite.ME server to add color-coded (code-hilited) parts to your documentation files, html-files, or other uses for hiliting your code is going well; then try using the static class Cache with your HLMP (HiLite Me Parameters). When there is a local cache of all your request operations to the HiLite.ME server, the code will first check that a local copy of the results for you code-hiliting exits.

    WHEN: The cache will be used, instead of request to the server in the following cases:

    • If a local copy of a source-code snippet is found in the cache, whose contents are identical.
    • If the HiLite.ME style-tag requested is identical to the last polling of the server
    • If the HiLite.ME code-type-tag requested is identical to the one in the cache.


    FASTER BUILDS: If a build perpetually is taking minutes to hilite code snippets in every source-file of your class hierarchy, but most of the code in your classes rarely changes, then creating a directory where caches results can be saved will improve build times tremendously.



    • Constructor Detail

      • Cache

        public Cache​(java.lang.String cacheSaveDirectory)
              throws CacheError
        This will load the hashCodes table to memory from the file-system directory identified by parameter String cacheSaveDirectory. An exception shall be thrown if this file is not found.
        Parameters:
        cacheSaveDirectory - This constructor presumes that this cache has been used and visited before. This directory name should point to your local-cache of the HiLite.ME Server Code hilite past-operations.
        Throws:
        CacheError - This error will throw if the cache has not been instantiated, or is corrupted. If the specified directory does not exist, then this Error shall also throw. The chain-cause Throwable should be visible, and is included as the Throwable.getCause().
    • Method Detail

      • totalSize

        public long totalSize()
        Inform the user how much space (in bytes) is used by this Cache.
        Returns:
        The number of bytes being used on the file-system by this Cache.
        Code:
        Exact Method Body:
        1
         return FileNode.createRoot(cacheSaveDirectory).loadTree().getDirTotalContentsSize();
        
      • totalNumber

        public int totalNumber()
        Count how many files and directories are contained in this Cache.
        Returns:
        The total number of files and sub-directories in the Cache directory.
        Code:
        Exact Method Body:
        1
         return FileNode.createRoot(cacheSaveDirectory).loadTree().count();
        
      • persistMasterHashToDisk

        public void persistMasterHashToDisk()
                                     throws CacheError
        This will save the hash-table to disk. The master hash-table just keeps a list of the strings that are cached to disk.
        Throws:
        CacheError - This Error will throw if there is a problem writing the master cache-hash to disk. The chain-cause Throwable should be visible, and is included as the Throwable.getCause()
        Code:
        Exact Method Body:
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10
        11
        12
        13
        14
        15
         try
         {
             FileRW.writeObjectToFile
                 (hashCodes, this.cacheSaveDirectory + HASH_SAVE_TREE, true);
         } 
         catch (Throwable t)
         {
             throw new CacheError(
                 "There was an error writing the Master Hash-Code table to disk. " +
                 "File [" + this.cacheSaveDirectory + HASH_SAVE_TREE + "] was not saved. " +
                 "The cache-file will have to be refreshed at some point.  New Files " +
                 "Cache-Hash not saved.",
                 t
             );
         }
        
      • rebuildMasterHashCache

        public void rebuildMasterHashCache()
        Will write this method soon. It currently is not written.
        Code:
        Exact Method Body:
        1
         // TO DO
        
      • initializeOrClear

        public static HiLiteMe.Cache initializeOrClear​
                    (java.lang.String cacheSaveDirectory,
                     StorageWriter sw)
                throws CacheError
        
        This will initialize a cache-file in the file-system directory identified by parameter String cacheSaveDirectory. If the directory specified does not exist, a CacheError is thrown. Any old cache files will be removed. To attempt to preserve old cache-files, call method initializeOrRepair(String, StorageWriter)

        OrClear: If the directory structure provided to this initialize method is not empty, the its entire contents shall be erased by a call to (Below)

        Java Line of Code:
        1
        2
        3
         FileTransfer.deleteFilesRecursive
             (FileNode.createRoot(cacheSaveDirectory).loadTree(), sw);
         
        
        Parameters:
        cacheSaveDirectory - This constructor presumes that this cache has been used and visited before. This directory name should point to your local-cache of HiLite.ME Server Code hilite past-operations.
        Throws:
        CacheError - This exception will be throw if there are errors deleting any old-cache files currently in the directory; or if there is any error creating the new master hash-cache file. The chain-cause Throwable should be visible, and is included as the Throwable.getCause().
        Code:
        Exact Method Body:
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        22
        23
        24
        25
        26
        27
        28
        29
        30
        31
        32
        33
        34
        35
        36
         cacheSaveDirectory = checkCSD(cacheSaveDirectory);
         final String tempStrForStupidLambdaFinalBS = cacheSaveDirectory;
        
         try
         {
             File f = new File(cacheSaveDirectory);
             if (f.isDirectory())
                 FileTransfer.deleteFilesRecursive(
                     FileNode.createRoot(cacheSaveDirectory).loadTree(), null,
                     (FileNode fn) -> fn.getFullPathName().equals(tempStrForStupidLambdaFinalBS),
                     sw
                 );
             f.mkdirs();
         }
         catch (Throwable t)
         {
             throw new CacheError(
                 "There was an error emptying/clearing the directory [" + cacheSaveDirectory + "] " +
                 "of it's contents, please see cause throwable.getCause() for details.",
                 t
             );
         }
        
         try
             { writeNewTS(cacheSaveDirectory); }
         catch (Throwable t)
         {
             throw new CacheError(
                 "There was an error saving/creating the new cache-file " +
                 "[" + cacheSaveDirectory + "], please see cause chain throwable.getCause(), " +
                 "for more details.",
                 t
             );
         }
        
         return new Cache(cacheSaveDirectory);