CkCache class final
Store, retrieve, expire, and clean up cached text or binary data on disk.
CkCache 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
Store and retrieve cached items by unique key, without the application needing to manage the underlying cache filenames directly.
Text and binary data
Cache strings, byte data, files, or Chilkat buffer objects depending on the data form used by the application.
Expiration control
Associate cached items with expiration times, update expiration metadata, and check whether cached content is still usable.
ETag metadata
Store and retrieve ETag values for workflows that need HTTP-style cache validation or conditional re-fetch logic.
Configurable layout
Choose the cache root directory and use an optional multi-level directory structure to avoid too many files in a single folder.
Cleanup operations
Delete a single cached item, remove expired items, remove older items, or clear the entire cache when needed.
Common pattern: Configure the cache root, choose the key used to identify each item, check whether a valid cached copy exists, fetch or regenerate the content when needed, store it with expiration and optional ETag metadata, and periodically clean up expired or old cached items.
For an extended overview, see Cache Class Overview.
A CkCache owns a native Chilkat object. It is released automatically when the
Dart object is garbage collected, or immediately by dispose. Use it only from
the isolate that created it.
- Implemented types
Constructors
- CkCache()
-
Creates a new
CkCacheobject.
Properties
- debugLogFilePath ↔ String
-
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.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDisposed → bool
-
Whether dispose has been called on this object.
no setter
- lastErrorHtml → String
-
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.
no setter
- lastErrorText → String
-
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.
no setter
- lastErrorXml → String
-
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.
no setter
- lastEtagFetched → String
-
Returns the ETag metadata associated with the most recently fetched cache
item. An empty string means that the fetched item has no stored ETag.
no setter
- lastExpirationFetchedStr → String
-
Returns the expiration date and time stored for the most recently fetched
cache item, formatted as an RFC 822-style Internet date. An empty string
represents an item with no expiration date.
no setter
- lastHitExpired → bool
-
Returns
truewhen the expiration time of the most recently fetched item is earlier than the current system date and time; otherwise returnsfalse.no setter - lastKeyFetched → String
-
Returns the application-defined key associated with the most recently
fetched cache item.
no setter
- lastMethodSuccess ↔ bool
-
Indicates the success or failure of the most recent method call:
truemeans success,falsemeans 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.getter/setter pair - level ↔ int
-
Gets or sets the number of directory levels used beneath each cache root.
Valid values are
0,1, and2.getter/setter pair - numRoots → int
-
Returns the number of cache-root directories that have been registered by
calling addRoot.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- verboseLogging ↔ bool
-
If set to
true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value isfalse. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.getter/setter pair - version → String
-
Version of the component/library, such as "10.1.0"
no setter
Methods
-
addRoot(
String path) → void -
Adds
pathas a root directory for the disk cache. Call this method once for each root that should participate in the cache. -
deleteAll(
) → int - Deletes every cache item from all configured roots and returns the number of cache files removed. Multi-level subdirectories are retained.
-
deleteAllExpired(
) → int - Deletes all cache items whose stored expiration time is earlier than the current system time and returns the number of files removed.
-
deleteFromCache(
String key) → void -
Deletes the cache item identified by
key. -
deleteOlderDt(
CkDateTime dt) → int -
Deletes cache items older than the cutoff date and time supplied in
dt. -
deleteOlderStr(
String dateTimeStr) → int -
Deletes cache items older than the cutoff date and time supplied in
dateTimeStras an RFC 822-style Internet date string. -
dispose(
) → void - Releases the native object now instead of waiting for garbage collection.
-
fetchBd(
String key, CkBinData bd) → void -
Retrieves the binary item identified by
keyand loads its bytes into theBinDataobject supplied inbd. -
fetchSb(
String key, CkStringBuilder sb) → void -
Retrieves the text item identified by
keyand loads its content into theStringBuildersupplied insb. -
fetchText(
String key) → String -
Retrieves the text item identified by
keyand returns its string content. -
getEtag(
String key) → String -
Returns the ETag metadata stored with the cache item identified by
key. -
getExpirationStr(
String url) → String -
Returns the expiration date and time stored for the item identified by
url, formatted as an RFC 822-style Internet date string. -
getFilename(
String key) → String -
Returns the absolute filesystem path of the cache file associated with
key. -
getRoot(
int index) → String -
Returns the directory path of the cache root at zero-based
index. Valid indexes range from0through0 - 1. -
isCached(
String key) → bool -
Returns
trueif an item exists forkey, orfalseif the key is not present. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
saveBd(
String key, String expiration, String etag, CkBinData bd) → void -
Stores the contents of
bdas binary cache data underkey. If the key already exists, its data and metadata are replaced. -
saveTextDt(
String key, CkDateTime expireDateTime, String eTag, String itemTextData) → void -
Stores
itemTextDataas a text cache item underkey, with the expiration date and time supplied inexpireDateTime. If the key already exists, its data and metadata are replaced. -
saveTextNoExpire(
String key, String eTag, String itemTextData) → void -
Stores
itemTextDataas a non-expiring text cache item underkey. If the key already exists, its data and metadata are replaced. -
saveTextStr(
String key, String expireDateTime, String eTag, String itemTextData) → void -
Stores
itemTextDataas a text cache item underkey, withexpireDateTimeproviding the expiration time as an RFC 822-style Internet date string. If the key already exists, its data and metadata are replaced. -
toString(
) → String -
A string representation of this object.
override
-
updateExpirationDt(
String key, CkDateTime expireDateTime) → void -
Replaces the expiration date and time of the cache item identified by
keywith theCkDateTimevalue supplied inexpireDateTime. The cached data and ETag are unchanged. -
updateExpirationStr(
String key, String expireDateTime) → void -
Replaces the expiration date and time of the cache item identified by
keywith the RFC 822-style Internet date string supplied inexpireDateTime. The cached data and ETag are unchanged.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited