Cache Tcl Reference Documentation
Cache
Current Version: 11.5.0
Chilkat.Cache
Store and retrieve cached items by unique key, without the application
needing to manage the underlying cache filenames directly.
Cache strings, byte data, files, or Chilkat buffer objects depending on
the data form used by the application.
Associate cached items with expiration times, update expiration metadata,
and check whether cached content is still usable.
Store and retrieve ETag values for workflows that need HTTP-style cache
validation or conditional re-fetch logic.
Choose the cache root directory and use an optional multi-level directory
structure to avoid too many files in a single folder.
Delete a single cached item, remove expired items, remove older items, or
clear the entire cache when needed.
For an extended overview, see
Cache Class Overview.
Store, retrieve, expire, and clean up cached text or binary data on disk.
Chilkat.Cache is a disk-based cache class for storing and
retrieving text or binary items by unique key. It provides configurable cache
roots, optional multi-level directory layout, expiration metadata, ETag
metadata, cache lookup, fetch-status properties, expiration updates, and
cleanup methods for deleting individual items, expired items, older items, or
the entire cache.
Key-based storage
Text and binary data
Expiration control
ETag metadata
Configurable layout
Cleanup operations
Object Creation
# 'this' is not a keyword in Tcl. It can freely be used as a variable name. set this [new CkCache]
Properties
DebugLogFilePath
# ckStr is a CkString
CkCache_get_DebugLogFilePath $this $ckStr
set strVal [CkCache_get_debugLogFilePath $this]
CkCache_put_DebugLogFilePath $this $strVal
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
LastErrorHtml
# ckStr is a CkString
CkCache_get_LastErrorHtml $this $ckStr
set strVal [CkCache_get_lastErrorHtml $this]
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
# ckStr is a CkString
CkCache_get_LastErrorText $this $ckStr
set strVal [CkCache_get_lastErrorText $this]
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
# ckStr is a CkString
CkCache_get_LastErrorXml $this $ckStr
set strVal [CkCache_get_lastErrorXml $this]
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastEtagFetched
# ckStr is a CkString
CkCache_get_LastEtagFetched $this $ckStr
set strVal [CkCache_get_lastEtagFetched $this]
The ETag of the last item fetched from cache.
topLastExpirationFetchedStr
# ckStr is a CkString
CkCache_get_LastExpirationFetchedStr $this $ckStr
set strVal [CkCache_get_lastExpirationFetchedStr $this]
Expiration date/time of the last item fetched from cache in RFC822 string format.
topLastHitExpired
set boolVal [CkCache_get_LastHitExpired $this]
1 if the LastExpirationFetched is before the current date/time. Otherwise 0.
LastKeyFetched
# ckStr is a CkString
CkCache_get_LastKeyFetched $this $ckStr
set strVal [CkCache_get_lastKeyFetched $this]
The key of the last item fetched from cache. (For web pages, the key is typically the canonicalized URL. Otherwise, the key is a unique identifer used to access the cached item.)
topLastMethodSuccess
set boolVal [CkCache_get_LastMethodSuccess $this]
CkCache_put_LastMethodSuccess $this $boolVal
Indicates the success or failure of the most recent method call: 1 means success, 0 means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
Level
set intVal [CkCache_get_Level $this]
CkCache_put_Level $this $intVal
The number of directory levels in the cache. Possible values are:
0: All cache files are in a single directory (the cache root).top
1: Cache files are located in 256 sub-directories numbered 0 .. 255 directly under the cache root.
2: There are two levels of sub-directories under the cache root. The 1st level has 256 sub-directories numbered 0 .. 255 directly under the cache root. The 2nd level allows for up to 256 sub-directories (0..255) under each level-1 directory. Cache files are stored in the leaf directories.
NumRoots
set intVal [CkCache_get_NumRoots $this]
The number of root directories composing the cache. A typical multi-root cache would place each root on a separate hard drive.
topUtf8
set boolVal [CkCache_get_Utf8 $this]
CkCache_put_Utf8 $this $boolVal
When set to 1, all string arguments and return values are interpreted as UTF-8 strings. When set to 0, they are interpreted as ANSI strings.
In Chilkat v11.0.0 and later, the default value is 1. Before v11.0.0, it was 0.
VerboseLogging
set boolVal [CkCache_get_VerboseLogging $this]
CkCache_put_VerboseLogging $this $boolVal
If set to 1, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is 0. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
# ckStr is a CkString
CkCache_get_Version $this $ckStr
set strVal [CkCache_get_version $this]
Methods
AddRoot
CkCache_AddRoot $this $path
Must be called once for each cache root. For example, if the cache is spread across D:\cacheRoot, E:\cacheRoot, and F:\cacheRoot, an application would setup the cache object by calling AddRoot three times -- once with D:\cacheRoot, once with E:\cacheRoot, and once with F:\cacheRoot.
DeleteAll
Deletes all items in the cache. This method completely clears the cache. All files in the cache are deleted. (If the cache is multi-level, existing sub-directories are not deleted.)
Returns the number of items (i.e. cache files) deleted.
topDeleteAllExpired
Deletes all expired items from the cache.
Returns the number of items (i.e. cache files) deleted.
topDeleteFromCache
set status [CkCache_DeleteFromCache $this $key]
Deletes a single item from the disk cache. Returns 0 if the item exists in cache but could not be deleted. Otherwise returns 1.
Returns 1 for success, 0 for failure.
topDeleteOlderDt
set retInt [CkCache_DeleteOlderDt $this $dateTime]
Deletes all items older than a specified date/time.
Returns the number of items (i.e. cache files) deleted. Returns -1 on error.
topDeleteOlderStr
set retInt [CkCache_DeleteOlderStr $this $dateTimeStr]
Deletes all items older than a specified date/time.
Returns the number of items (i.e. cache files) deleted. The dateTimeStr is passed as a date/time in RFC822 format. Returns -1 on error.
FetchBd
# bd is a CkBinData
set status [CkCache_FetchBd $this $key $bd]
Fetches an item from cache and returns in bd.
The key may be any length and may include any characters. It should uniquely identify the cached item. (No two items in the cache should have the same key.)
Returns 1 for success, 0 for failure.
topFetchSb
# sb is a CkStringBuilder
set status [CkCache_FetchSb $this $key $sb]
Fetches a text item from the cache and returns in sb.
The key may be any length and may include any characters. It should uniquely identify the cached item. (No two items in the cache should have the same key.)
Returns 1 for success, 0 for failure.
topFetchText
# outStr is a CkString (output)
set status [CkCache_FetchText $this $key $outStr]
set retStr [CkCache_fetchText $this $key]
Fetches a text item from the cache and returns it's text content.
The key may be any length and may include any characters. It should uniquely identify the cached item. (No two items in the cache should have the same key.)
Returns 1 for success, 0 for failure.
GetEtag
# outStr is a CkString (output)
set status [CkCache_GetEtag $this $key $outStr]
set retStr [CkCache_getEtag $this $key]
GetExpirationStr
# outStr is a CkString (output)
set status [CkCache_GetExpirationStr $this $url $outStr]
set retStr [CkCache_getExpirationStr $this $url]
Returns the expiration date/time for an item in the cache in RFC822 string format.
Returns 1 for success, 0 for failure.
topGetFilename
# outStr is a CkString (output)
set status [CkCache_GetFilename $this $key $outStr]
set retStr [CkCache_getFilename $this $key]
Returns the absolute file path of the cache file associated with the key.
Returns 1 for success, 0 for failure.
topGetRoot
# outStr is a CkString (output)
set status [CkCache_GetRoot $this $index $outStr]
set retStr [CkCache_getRoot $this $index]
Returns the directory path of the Nth cache root. (Indexing begins at 0.)
Returns 1 for success, 0 for failure.
topIsCached
set retBool [CkCache_IsCached $this $key]
Returns 1 if the item is found in the cache, otherwise returns 0.
SaveBd
# expiration is a string
# etag is a string
# bd is a CkBinData
set status [CkCache_SaveBd $this $key $expiration $etag $bd]
Saves the contents of bd to the cache. expiration is the expiration date/time in RFC822 format; use an empty string if there is no expiration date. etag is optional metadata called an entity tag that can also be an empty string. key is a unique identifier for the cached item; it can be of any length and contain any characters, but must be unique to prevent duplication in the cache.
Returns 1 for success, 0 for failure.
topSaveTextDt
# expireDateTime is a CkDateTime
# eTag is a string
# itemTextData is a string
set status [CkCache_SaveTextDt $this $key $expireDateTime $eTag $itemTextData]
Inserts or replaces an text item in the cache. The eTag is optional and may be set to a zero-length string. Applications may use it as a place to save additional information about the cached item. The key may be any length and may include any characters. It should uniquely identify the cached item. (No two items in the cache should have the same key.)
Returns 1 for success, 0 for failure.
topSaveTextNoExpire
# eTag is a string
# itemTextData is a string
set status [CkCache_SaveTextNoExpire $this $key $eTag $itemTextData]
Inserts or replaces an text item in the cache with no expiration date/time. The eTag is optional and may be set to a zero-length string. Applications may use it as a place to save additional information about the cached item.
Returns 1 for success, 0 for failure.
SaveTextStr
# expireDateTime is a string
# eTag is a string
# itemTextData is a string
set status [CkCache_SaveTextStr $this $key $expireDateTime $eTag $itemTextData]
The same as SaveText, except the expire date/time is passed as a string in RFC822 format.
Returns 1 for success, 0 for failure.
topUpdateExpirationDt
# expireDateTime is a CkDateTime
set status [CkCache_UpdateExpirationDt $this $key $expireDateTime]
UpdateExpirationStr
# expireDateTime is a string
set status [CkCache_UpdateExpirationStr $this $key $expireDateTime]
The same as UpdateExpiration, except the expireDateTime is passed in RFC822 string format.
Returns 1 for success, 0 for failure.
topDeprecated
FetchFromCache Deprecated
# outBytes is a CkByteData (output)
set status [CkCache_FetchFromCache $this $key $outData]
Fetches an item from cache.
The key may be any length and may include any characters. It should uniquely identify the cached item. (No two items in the cache should have the same key.)
Returns 1 for success, 0 for failure.
topGetExpirationDt
# key is a string
set ret_ckDateTime [CkCache_GetExpirationDt $this $key]
Returns the expiration date/time for an item in the cache as a CkDateTime object.
Returns NULL on failure
SaveToCacheDt Deprecated
# expireDateTime is a CkDateTime
# eTag is a string
# itemData is a CkByteData
set status [CkCache_SaveToCacheDt $this $key $expireDateTime $eTag $itemData]
Inserts or replaces an item in the cache. The eTag is optional and may be set to a zero-length string. Applications may use it as a place to save additional information about the cached item. (Chilkat.Http when caching a page, writes the eTag (entity-tag) from the HTTP response header to this field.)
The key may be any length and may include any characters. It should uniquely identify the cached item. (No two items in the cache should have the same key.)
Returns 1 for success, 0 for failure.
topSaveToCacheNoExpire Deprecated
# eTag is a string
# itemData is a CkByteData
set status [CkCache_SaveToCacheNoExpire $this $key $eTag $itemData]
Inserts or replaces an item in the cache. The cached item will have no expiration. The eTag is optional and may be set to a zero-length string. Applications may use it as a place to save additional information about the cached item.
Returns 1 for success, 0 for failure.
topSaveToCacheStr Deprecated
# expireDateTime is a string
# eTag is a string
# itemData is a CkByteData
set status [CkCache_SaveToCacheStr $this $key $expireDateTime $eTag $itemData]
The same as SaveToCache, except the expire date/time is passed in RFC822 string format.
Returns 1 for success, 0 for failure.
top