Package Torello.Java
Class HiLiteMe.Cache
- java.lang.Object
-
- Torello.Java.HiLiteMe.Cache
-
- Enclosing class:
- HiLiteMe
public static class HiLiteMe.Cache extends java.lang.Object
A caching-system class that allows this tool to efficiently bypass calls to the server when an exact-copy of the hilited source-code already exists inside the cache.
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 thestatic class Cache
with yourHLMP
(HiLite Me Parameters). When there is a local cache of all your request operations to theHiLite.ME
server, the code will first check that a local copy of the results for you code-hiliting exits.
The cache will be used, instead of request to the server under the following conditions:- 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 Build:
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.
Hi-Lited Source-Code:- View Here: Torello/Java/HiLiteMe.java
- Open New Browser-Tab: Torello/Java/HiLiteMe.java
File Size: 13,443 Bytes Line Count: 321 '\n' Characters Found
-
-
Constructor Summary
Constructors Constructor Description Cache(String cacheSaveDirectory)
This will load the hashCodes table to memory from the file-system directory identified byString
-Parameter'cacheSaveDirectory'
.
-
Method Summary
Initializing either a new, or existing, Cache Modifier and Type Method static HiLiteMe.Cache
initializeOrClear(String cacheSaveDirectory, StorageWriter sw)
Master-Cache File-Hashes List Modifier and Type Method void
persistMasterHashToDisk()
void
rebuildMasterHashCache()
Cache Information & Stats Modifier and Type Method int
totalNumber()
long
totalSize()
-
-
-
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 byString
-Parameter'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 theHiLite.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 thisError
shall also throw. The chain-causeThrowable
should be visible, and is included as theThrowable.getCause()
.
-
-
Method Detail
-
totalSize
public long totalSize()
Inform the user how much space (in bytes) is used by thisCache
.- Returns:
- The number of bytes being used on the file-system by this
Cache
. - Code:
- Exact Method Body:
return FileNode.createRoot(cacheSaveDirectory).loadTree().getDirTotalContentsSize();
-
totalNumber
public int totalNumber()
Count how many files and directories are contained in thisCache
.- Returns:
- The total number of files and sub-directories in the
Cache
directory. - Code:
- Exact Method Body:
return FileNode.createRoot(cacheSaveDirectory).loadTree().count();
-
persistMasterHashToDisk
public void persistMasterHashToDisk() throws CacheError
This will save the hash-codeTreeSet<Integer>
to disk. The Master Hash-Code List just keeps a record of the hashcodes of everyString
that was hilited by the Hiliter (and therefore saved inside the Cache). This method will save that JavaTreeSet
of Hash-Codes to disk.- Throws:
CacheError
- ThisError
will throw if there is a problem writing the master cache-hash to disk. The chain-causeThrowable
should be visible, and is included as theThrowable.getCause()
- Code:
- Exact Method Body:
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.
-
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 parameterString cacheSaveDirectory
. If the directory specified does not exist, aCacheError
is thrown. Any old cache files will be removed. To attempt to preserve old cache-files, call methodinitializeOrRepair(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:
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 ofHiLite.ME
Server Code hilite past-operations.sw
- This receives log-writes from the call toFileTransfer.deleteFilesRecursive(Torello.Java.FileNode, Torello.Java.FileNodeFilter, Torello.Java.FileNodeFilter, java.lang.Appendable)
which clears the files currently in the cache. This parameter may be null, and if it is, output-text will be shunted.- 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-causeThrowable
should be visible, and is included as theThrowable.getCause()
.- Code:
- Exact Method Body:
cacheSaveDirectory = checkCSD(cacheSaveDirectory); final String tempStrForStupidLambdaFinal = cacheSaveDirectory; try { File f = new File(cacheSaveDirectory); if (f.isDirectory()) FileTransfer.deleteFilesRecursive( FileNode.createRoot(cacheSaveDirectory).loadTree(), null, (FileNode fn) -> fn.getFullPathName().equals(tempStrForStupidLambdaFinal), 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);
-
-