Struct cbfsconnect::CBCache

Properties   Methods   Events   Config Settings   Errors  

The CBCache struct allows applications to easily cache remote file data locally.

Syntax

cbfsconnect::CBCache

Remarks

The CBCache struct provides a local file-caching implementation that helps applications easily cache the contents of files stored in some external storage, such as a cloud storage service. Once an application has informed the CBCache struct of the external storage's file transfer capabilities, the hard work of reading data into and flushing data out of the cache is handled automatically.

Getting Started

Applications typically need only a single instance of the CBCache struct, because it can handle caching and accessing multiple files at once in parallel. Each file in the cache is identified by its file Id, and all cached file data are stored in a single cache storage file, whose name and location are determined by the cache_file and cache_directory properties, respectively.

In terms of application architecture, the CBCache struct (or, more generally, the cache itself) should reside between application code that needs random access to files in the external storage, and the code that provides access to said external storage. The former makes use of the CBCache struct's properties and methods, while the latter is "connected" through the struct's on_read_data and on_write_data events.

Here's how to get up and running:

  1. Implement the on_read_data and on_write_data events so that they provide appropriate access to the external storage. The on_read_data event is mandatory. The on_write_data event is required only if the CBCache struct is to be in charge of flushing changed data back to external storage. Refer to these events' documentation for more information about how to correctly implement them.
  2. "Describe" the reading, writing, and resizing capabilities of the external storage to the CBCache struct by setting the reading_capabilities, writing_capabilities, and resizing_capabilities properties. This information is used by the CBCache struct to formulate a strategy for interacting with the external storage through the events mentioned in step 1.
  3. Open the cache by setting the cache_directory and cache_file properties, and then calling the open_cache method.
  4. When the struct opens an existing cache vault, it is recommended that applications use the enumerate_cached_files method to search for any Orphan Files (i.e., files that are not currently open have unflushed data). If any such files are found, applications may wish to open, flush, or delete them.
  5. To create or open a file in the cache (i.e., a cached file), call the file_open method.
  6. While a cached file is open, it can be read from or written to using the file_read and file_write methods.

Object Lifetime

The new() method returns a mutable reference to a struct instance. The object itself is kept in the global list maintainted by CBFSConnect. Due to this, the CBCache struct cannot be disposed of automatically. Please, call the dispose(&mut self) method of CBCache when you have finished using the instance.

Property List


The following is the full list of the properties of the struct with short descriptions. Click on the links for further details.

activeThis property describes whether the file cache is open.
auto_flushThis property specifies whether automatic flushing is enabled.
cache_directoryThis property includes the directory in which the cache's storage file is located.
cache_fileThis property includes the name of the file cache.
cache_size_limitThis property includes the maximum size of the cache's storage file.
compressedThis property specifies whether or not the cache's storage file should be compressed.
flush_after_close_delayThis property includes the number of seconds to delay flushing after a file is closed.
flush_after_sizeThis property includes the amount of data that must be changed for flushing to begin.
flush_after_timeThis property includes the inactivity timeout that must elapse for flushing to begin.
flush_policyThis property includes the file flushing strategy that the cache should use.
has_orphansThis property notes whether or not the cache contains any orphan files.
max_cached_file_sizeThis property includes the maximum amount of data that should be cached for any given file.
modeThis property includes the mode in which the cache operates in regard to access to the external storage.
offlineThis property specifies whether or not the cache works in Offline mode.
purge_after_close_delayThis property includes the number of seconds to delay purging for after a file is closed.
purge_after_timeThis property includes the inactivity timeout that must elapse for purging to begin.
purge_policyThis property includes the file block purging strategy that the cache should use.
read_block_sizeThis property includes the block size to use when reading file data from external storage.
reading_capabilitiesThis property includes the reading capabilities supported by the external storage.
resizing_capabilitiesThis property includes the file resizing capabilities supported by the external storage.
serializationThis property specifies whether nonintersecting operations against the same file or cache should execute serially or in parallel.
stats_cache_sizeThis property contains the current size of the cache.
stats_current_file_idThis property contains the file currently being read or written by the cache.
stats_current_operationThis property contains the operation currently being performed by the cache.
stats_total_dataThis property contains the total amount of data present in the cache.
stats_unflushed_dataThis property contains the amount of unflushed data present in the cache.
stats_unflushed_filesThis property contains the number of unflushed files present in the cache.
tagThis property stores application-defined data specific to a particular instance of the struct.
write_block_sizeThis property includes the block size to use when writing file data to external storage.
writing_capabilitiesThis property includes the writing capabilities supported by the external storage.

Method List


The following is the full list of the methods of the struct with short descriptions. Click on the links for further details.

cancel_cleanupThis method cancels a background cleanup operation, if necessary.
check_and_repairThis method checks a cache vault's consistency and repairs it as necessary.
clearThis method removes files from the cache.
close_cacheThis method closes the cache.
close_enumerationThis method closes the given file enumeration.
configSets or retrieves a configuration setting.
delete_cacheThis method deletes the cache completely.
enumerate_cached_filesThis method enumerates the files in the cache.
file_change_idThis method changes the Id of a cached file.
file_closeThis method closes a cached file.
file_close_exThis method closes a cached file, specifying flushing and purging behaviors explicitly.
file_deleteThis method deletes a file from the cache.
file_existsThis method checks if a file with the given Id is present in the cache.
file_flushThis method flushes the specified file's modified blocks out to external storage.
file_get_pinnedThis method returns the pinned state of a cached file.
file_get_sizeThis method gets the "real size" of a cached file.
file_get_statusThis method gets the status of a cached file.
file_openThis method opens the specified cached file, creating it if necessary.
file_open_exThis method opens the specified cached file, creating it if necessary.
file_purgeThis method purges unmodified data from the cache.
file_readThis method reads the specified part of a cached file.
file_set_pinnedThis method sets the pinned state of a cached file.
file_set_sizeThis method sets the "real size" of a cached file.
file_set_size_exThis method sets the "real size" of a cached file.
file_tag_deleteThis method deletes a file tag.
file_tag_existsThis method checks whether or not a file has a specific tag associated with it.
file_tag_getThis method retrieves the binary data held by a file tag attached to the specified cached file.
file_tag_get_sizeThis method retrieves the size of a file tag attached to the specified cached file.
file_tag_setThis method attaches a file tag with binary data to the specified cached file.
file_touchThis method touches a range of data in a cached file.
file_writeThis method writes the specified part of a cached file.
get_next_enumerated_fileThis method returns the next file in the list of enumeration results.
open_cacheThis method opens the cache.
refresh_statisticsThis method forces a refresh of the cache's statistics.
reset_error_stateThis method resets any outstanding errors for a file or external storage.
start_cleanupThis method starts a background cleanup operation to remove unused files from the cache.

Event List


The following is the full list of the events fired by the struct with short descriptions. Click on the links for further details.

on_before_flushThis event fires to report the start of the asynchronous file flush procedure.
on_before_purgeThis event fires to report the start of the asynchronous file purge procedure.
on_end_cleanupThis event fires to report the beginning of the asynchronous cleanup procedure.
on_errorThis event fires if an unhandled error occurs during an event.
on_logThis log reports events that occur in the struct.
on_progressThis event fires to report the progress of an operation.
on_read_dataThis event fires when the cache needs to read file data from external storage.
on_start_cleanupThis event fires to report the beginning of the asynchronous cleanup procedure.
on_statusThis event fires to report the latest cache statistics.
on_write_dataThis event fires when the cache needs to write file data to external storage.

Config Settings


The following is a list of config settings for the struct with short descriptions. Click on the links for further details.

BlockSizeThe size of the block, used to store the data.
JournalingModeSpecifies whether the main cache file uses journaling for increased data consistency.
LogLevelThe level of detail that is logged.
MaxReaderThreadsPerFileThe maximum number of reader threads to use to fire events.
StatsRefreshIntervalMinimum time period between cache statistics refreshes.
StoreDataInFilesSpecifies whether file data should be stored in the main cache file or in individual files.
BuildInfoInformation about the product's build.
LicenseInfoInformation about the current license.

active Property (CBCache Struct)

This property describes whether the file cache is open.

Syntax

fn active(&self ) -> Result<bool, CBFSConnectError> 

Default Value

false

Remarks

This property reflects whether the struct has opened a file cache; it will be true once the open_cache method has been called successfully.

This property is read-only.

Data Type

bool

auto_flush Property (CBCache Struct)

This property specifies whether automatic flushing is enabled.

Syntax

fn auto_flush(&self ) -> Result<bool, CBFSConnectError> 
fn set_auto_flush(&self, value : bool) -> Option<CBFSConnectError>

Default Value

false

Remarks

This property specifies whether automatic flushing is enabled. When this property is enabled (default), automatic flushing will take place both according to the flush_policy setting, and when cached files are closed (after any delay specified by the flush_after_close_delay property).

If this property is disabled, automatic flushing will never occur, regardless of the flush_policy setting; however, the file_flush method can still be used to explicitly flush a cached file.

Typically, applications should disable this property only in cases in which they need to suspend background write operations for some reason (e.g., if connectivity with the external storage is temporarily lost).

Data Type

bool

cache_directory Property (CBCache Struct)

This property includes the directory in which the cache's storage file is located.

Syntax

fn cache_directory(&self ) -> Result<String, CBFSConnectError> 
fn set_cache_directory(&self, value : String) -> Option<CBFSConnectError> fn set_cache_directory_ref(&self, value : &String) -> Option<CBFSConnectError>

Default Value

String::default()

Remarks

This property specifies the path of the directory in which the cache's storage file is located. The name of the cache's storage file is derived from the cache_file property.

Note: This property cannot be changed when active is true.

Data Type

String

cache_file Property (CBCache Struct)

This property includes the name of the file cache.

Syntax

fn cache_file(&self ) -> Result<String, CBFSConnectError> 
fn set_cache_file(&self, value : String) -> Option<CBFSConnectError> fn set_cache_file_ref(&self, value : &String) -> Option<CBFSConnectError>

Default Value

String::default()

Remarks

This property specifies the name of the file cache. This name is used to create the cache's storage file in the directory specified by the cache_directory property.

Note: This property cannot be changed when active is true.

Data Type

String

cache_size_limit Property (CBCache Struct)

This property includes the maximum size of the cache's storage file.

Syntax

fn cache_size_limit(&self ) -> Result<i32, CBFSConnectError> 
fn set_cache_size_limit(&self, value : i32) -> Option<CBFSConnectError>

Default Value

0

Remarks

This property specifies the maximum size, in megabytes, that the cache's storage file is allowed to grow to. If this limit is reached, the cache will initiate a background cleanup operation automatically, purging file data according to the purge_policy and shrinking the cache storage file afterward. By default, this property is set to 0, which means "no limit".

Note: Any purging and shrinking attempts caused by this property's value are made on a "best effort" basis, which can be affected by the following:

  • The amount of unflushed data present in the cache (as indicated by the stats property): if it is greater than the specified size limit, the cache will not be able to purge said data or shrink its storage file until enough data have been flushed.
  • The purge_policy property: certain values can make it impossible for the cache to immediately perform the required purging.

Note: This property cannot be changed when active is true.

Data Type

i32

compressed Property (CBCache Struct)

This property specifies whether or not the cache's storage file should be compressed.

Syntax

fn compressed(&self ) -> Result<bool, CBFSConnectError> 
fn set_compressed(&self, value : bool) -> Option<CBFSConnectError>

Default Value

false

Remarks

This property specifies whether or not the cache's storage file should be compressed.

If the StoreDataInFiles configuration setting is enabled, the Compressed property affects only the main cache storage file and not the files used to store individual files' data.

Note: This property cannot be changed when active is true.

Data Type

bool

flush_after_close_delay Property (CBCache Struct)

This property includes the number of seconds to delay flushing after a file is closed.

Syntax

fn flush_after_close_delay(&self ) -> Result<i32, CBFSConnectError> 
fn set_flush_after_close_delay(&self, value : i32) -> Option<CBFSConnectError>

Default Value

0

Remarks

This property specifies the number of seconds that flushing will be delayed after a file with unflushed blocks is closed. A value of 0 will cause such files to be flushed immediately upon close.

Flush-after-close delays are intended to prevent excessive flushing operations in cases in which a file is opened, written to, and closed many times in succession within the delay period.

Note: This property cannot be changed when active is true.

Data Type

i32

flush_after_size Property (CBCache Struct)

This property includes the amount of data that must be changed for flushing to begin.

Syntax

fn flush_after_size(&self ) -> Result<i32, CBFSConnectError> 
fn set_flush_after_size(&self, value : i32) -> Option<CBFSConnectError>

Default Value

0

Remarks

When the flush_policy property is set to fpSize, fpSizeOrTime, or fpSizeAndTime, this property specifies how many megabytes of a file's data must be changed for flushing to begin.

Changed data thresholds are intended to prevent excessive flushing in cases in which data are written to the same range of a file many times in succession.

Note: This property cannot be changed when active is true.

Data Type

i32

flush_after_time Property (CBCache Struct)

This property includes the inactivity timeout that must elapse for flushing to begin.

Syntax

fn flush_after_time(&self ) -> Result<i32, CBFSConnectError> 
fn set_flush_after_time(&self, value : i32) -> Option<CBFSConnectError>

Default Value

0

Remarks

When the flush_policy property is set to fpTime, fpSizeOrTime, or fpSizeAndTime, this property specifies how many seconds of inactivity (i.e., time with no writes) must elapse for a file before flushing can begin.

Inactivity delays are intended to prevent excessive flushing in cases in which data are written to a file many times in succession within the inactivity period.

Note: This property cannot be changed when active is true.

Data Type

i32

flush_policy Property (CBCache Struct)

This property includes the file flushing strategy that the cache should use.

Syntax

fn flush_policy(&self ) -> Result<i32, CBFSConnectError> 
fn set_flush_policy(&self, value : i32) -> Option<CBFSConnectError>

Default Value

0

Remarks

This property specifies the strategy that the cache should use for flushing-changed file data of the opened file out to external storage. It must be set to one of the following values:

fpNone (0) No automatic flushing. Use this setting to have the file written only after it is closed. Use the flush_after_close_delay property to control the delay between file closing and writing of file data.
fpSize (1) Flush a file when the amount of changed data exceeds a certain limit. The flush_after_size property specifies the size limit.
fpTime (2) (default) Flush a file when it has not been written to for a certain amount of time. The flush_after_time property specifies the time limit.
fpSizeOrTime (3) Flush a file when the amount of changed data exceeds a certain limit OR when it has not been written to for a certain amount of time. The flush_after_size and flush_after_time properties specify the size and time limits, respectively.
fpSizeAndTime (4) Flush a file when the amount of changed data exceeds a certain limit AND when it has not been written to for a certain amount of time. The flush_after_size and flush_after_time properties specify the size and time limits, respectively.

Note: This property cannot be changed when active is true.

Data Type

i32

has_orphans Property (CBCache Struct)

This property notes whether or not the cache contains any orphan files.

Syntax

fn has_orphans(&self ) -> Result<bool, CBFSConnectError> 

Default Value

false

Remarks

This property specifies whether or not the cache contains any Orphan Files, returning true if so or false otherwise.

Note: This property returns a valid value only when active is true.

This property is read-only.

Data Type

bool

max_cached_file_size Property (CBCache Struct)

This property includes the maximum amount of data that should be cached for any given file.

Syntax

fn max_cached_file_size(&self ) -> Result<i64, CBFSConnectError> 
fn set_max_cached_file_size(&self, value : i64) -> Option<CBFSConnectError>

Default Value

0

Remarks

This property specifies the maximum amount of data, in bytes, that the cache should store for any given file. When a file reaches this limit, the cache will start dropping its least-recently accessed unchanged blocks.

The default value of 0 means "no limit", causing all file data to be kept in the cache at least until the file is closed (and possibly longer, depending on how the cache is configured).

Data Type

i64

mode Property (CBCache Struct)

This property includes the mode in which the cache operates in regard to access to the external storage.

Syntax

fn mode(&self ) -> Result<i32, CBFSConnectError> 
fn set_mode(&self, value : i32) -> Option<CBFSConnectError>

Default Value

0

Remarks

This property specifies the mode of operations that the cache should use for reading and writing the data. Possible values are as follows:

cmNormal (0) (default) Regular cached reading and writing are performed.
cmShadow (1) The cache reads the data from the external storage, but it does not do any writes.
cmPassthrough (2) The cache does not store file data locally and serves read/write requests by firing the corresponding events synchronously.
cmMirror (3) Reading is performed as in the Normal mode. Writing is done synchronously both to the local cache and to the external storage. The file_write method returns when the data are flushed to the external storage or if the error occurs during this operation.

Note: This property cannot be changed when active is true.

Data Type

i32

offline Property (CBCache Struct)

This property specifies whether or not the cache works in Offline mode.

Syntax

fn offline(&self ) -> Result<bool, CBFSConnectError> 
fn set_offline(&self, value : bool) -> Option<CBFSConnectError>

Default Value

false

Remarks

This property specifies whether or not the cache works in Offline mode. When in this mode, no events are fired to read or write data from/to the external storage.

This property is different from auto_flush: auto_flush prevents automated flushing but allows reading and manual flushing, whereas the Offline mode prevents both reading and writing, which means that application-initiated flushing does nothing as well.

Data Type

bool

purge_after_close_delay Property (CBCache Struct)

This property includes the number of seconds to delay purging for after a file is closed.

Syntax

fn purge_after_close_delay(&self ) -> Result<i32, CBFSConnectError> 
fn set_purge_after_close_delay(&self, value : i32) -> Option<CBFSConnectError>

Default Value

0

Remarks

When the purge_policy property is set to ppFileClose, this property specifies the number of seconds that purging will be delayed for after a file without any unflushed blocks is closed. A value of 0 will cause such files to be purged immediately on close.

Purge-after-close delays are intended to prevent excessive fetching of data from external storage in cases in which a file is opened and closed many times in succession within the delay period.

Note: This property cannot be changed when active is true.

Data Type

i32

purge_after_time Property (CBCache Struct)

This property includes the inactivity timeout that must elapse for purging to begin.

Syntax

fn purge_after_time(&self ) -> Result<i32, CBFSConnectError> 
fn set_purge_after_time(&self, value : i32) -> Option<CBFSConnectError>

Default Value

0

Remarks

When the purge_policy property is set to ppTime, this property specifies the number of seconds that a file data block must remain unchanged for before it is purged from the cache. Because the cache is intended for longer-time data storage and all data survive cache restart, the default value is 30 days.

Note: This property cannot be changed when active is true.

Data Type

i32

purge_policy Property (CBCache Struct)

This property includes the file block purging strategy that the cache should use.

Syntax

fn purge_policy(&self ) -> Result<i32, CBFSConnectError> 
fn set_purge_policy(&self, value : i32) -> Option<CBFSConnectError>

Default Value

0

Remarks

This property specifies the strategy that the cache should use for purging unmodified blocks of file data from the cache. It must be set to one of the following values:

ppNone (0) (default) No automatic purging. Use the start_cleanup method to perform cache cleanup.
ppFileClose (1) Purge files as they are closed (after a delay). The purge_after_close_delay property specifies the delay interval.
ppCacheClose (2) Purge files when the cache is closed (without a delay).
ppTime (3) Purge files when they have not been accessed for a certain time. The purge_after_time property specifies the time a file must not be accessed for it to be purged.

Note: This property cannot be changed when active is true.

Data Type

i32

read_block_size Property (CBCache Struct)

This property includes the block size to use when reading file data from external storage.

Syntax

fn read_block_size(&self ) -> Result<i32, CBFSConnectError> 
fn set_read_block_size(&self, value : i32) -> Option<CBFSConnectError>

Default Value

0

Remarks

This property specifies the block size, in bytes, that the struct should use when reading data from external storage through the on_read_data event.

Note: In some cases (e.g., when reading the last part of a file), the amount of requested data may be less than the value specified by this property.

Applications should always set this property to a reasonable value (or use the default value), even if the reading_capabilities property specifies that the external storage supports only whole-file reading.

This property may be overridden by the corresponding parameter of the file_open and file_set_size methods.

Changing this property causes the BlockSize configuration setting's value to be recalculated.

Note: This property cannot be changed when active is true.

Data Type

i32

reading_capabilities Property (CBCache Struct)

This property includes the reading capabilities supported by the external storage.

Syntax

fn reading_capabilities(&self ) -> Result<i32, CBFSConnectError> 
fn set_reading_capabilities(&self, value : i32) -> Option<CBFSConnectError>

Default Value

0

Remarks

This property specifies any and all behaviors of the external storage that are relevant when reading data from it. The struct will automatically alter its behavior based on this property's "description" of how the external storage is able to provide file data.

This property should be set by ORing together zero or more of the flags defined in the following. These flags are grouped by name to specify the operations to which they apply.

Flag Group Description
Position Flags with POS in the name describe where read and writes can occur from.
Size Flags with SIZE in the name describe the sizes of read and writes the external data source supports.
Write Flags with WRITE in the name describe flags that are specific to write operations.
Supplemental Flags with SUPPL in the name describe flags that are used to further specify the expectations of the external data source.

Reading and Writing Capability Flags (Position Related)

RWCAP_POS_SEQUENTIAL_FROM_BOF0x00000001No random access allowed; read/write operations must start at the beginning of a file.

When this flag is used in writing capabilities, the struct can initiate reading of missing data before writing the changes to build the complete dataset, which is required for correct write operations.

RWCAP_POS_BLOCK_MULTIPLE0x00000004Reading/writing is possible at positions that are multiple of the corresponding block size.

The read and write block sizes are specified by the read_block_size and write_block_size properties . When this flag is used in writing capabilities, the struct can initiate reading of missing data before writing the changes to build the complete dataset, which is required for correct write operations.

RWCAP_POS_RANDOM0x00000008Reading/writing is possible at any position.

When this flag is used, other flags can still alter the positions at which reading/writing are possible.

RWCAP_POS_SUPPL_ONLY_WITHIN_FILE0x00000010File position must remain in the range: 0 <= FilePos < FileSize

Reading and Writing Capability Flags (Size Related)

RWCAP_SIZE_WHOLE_FILE0x00000100Only whole-file reads/writes are possible; partial reads/writes are not supported.

Note:

  • The read_block_size and write_block_size properties should still be set to reasonable values when using this flag.
  • Use one of the other RWCAP_SIZE_* flags instead of this one if the external storage supports reading subsets of the file.
When this flag is used in writing capabilities, the struct can initiate reading of missing data before writing the changes to build the complete dataset, which is required for correct write operations.

RWCAP_SIZE_FIXED_BLOCKS_WITH_TAIL0x00000200Reads/writes must be done in blocks of a fixed size, except for the last block, which may be of any size.

When this flag is used in writing capabilities, the struct can initiate reading of missing data before writing the changes to build the complete dataset, which is required for correct write operations.

RWCAP_SIZE_FIXED_BLOCKS_NO_TAIL0x00000400Reads/writes must be done in blocks of a fixed size, including the last block.

Note: Real file sizes, if needed, must be stored elsewhere when using the cache with an external storage medium that has this characteristic.

When this flag is used in writing capabilities, the struct can initiate reading of missing data before writing the changes to build the complete dataset, which is required for correct write operations.

RWCAP_SIZE_ANY0x00000800Reads/writes may be done in blocks of any size.

Reading and Writing Capability Flags (Write Related)

RWCAP_WRITE_APPEND_ONLY0x00000002Append only; write operations must start at the end of a file.

To overwrite a file, it must first be truncated, and then written to. (Truncation behavior is defined by the corresponding flags.)

RWCAP_WRITE_SUPPL_NOT_BEYOND_EOF0x00000020File position remain in the range: 0 <= FilePos <= FileSize

When writing, appending to the end of the file is supported, but writing at positions past the end of the file is not.

RWCAP_WRITE_TRUNCATES_FILE0x00001000When writes occur, the last data written becomes the new end of the file.

Any overwritten data, and any data previously present after the written range, are lost.

RWCAP_WRITE_KEEPS_FILESIZE0x00002000Normal writing behavior (i.e., writes do not alter a file's size, except possibly to expand it).

RWCAP_WRITE_NOT_BEYOND_EOF0x00004000Writes may not extend past the end of a file's current size (i.e., cannot cause a file to grow).

Applications may still adjust the file size beforehand.

Note: This property cannot be changed when active is true.

Data Type

i32

resizing_capabilities Property (CBCache Struct)

This property includes the file resizing capabilities supported by the external storage.

Syntax

fn resizing_capabilities(&self ) -> Result<i32, CBFSConnectError> 
fn set_resizing_capabilities(&self, value : i32) -> Option<CBFSConnectError>

Default Value

0

Remarks

This property specifies any and all behaviors of the external storage that are relevant when resizing files. The struct will automatically alter its behavior based on this property's "description" of how the external storage is able to resize files.

This property should be set by ORing together zero or more of the following flags:

RSZCAP_GROW_TO_ANY0x00000001Files can grow to any size.

RSZCAP_SHRINK_TO_ANY0x00000002Files can shrink to any size.

RSZCAP_GROW_TO_BLOCK_MULTIPLE0x00000004Files can grow to sizes that are a multiple of the block size.

RSZCAP_SHRINK_TO_BLOCK_MULTIPLE0x00000008Files can shrink to sizes that are a multiple of the block size.

RSZCAP_TRUNCATE_ON_OPEN0x00000010The external storage (or application itself) supports truncating a file when it is opened for writing.

RSZCAP_TRUNCATE_AT_ZERO0x00000020The external storage (or application itself) supports truncating a file to zero at any time (not just when it is being opened).

Note: This property cannot be changed when active is true.

Data Type

i32

serialization Property (CBCache Struct)

This property specifies whether nonintersecting operations against the same file or cache should execute serially or in parallel.

Syntax

fn serialization(&self ) -> Result<i32, CBFSConnectError> 
fn set_serialization(&self, value : i32) -> Option<CBFSConnectError>

Default Value

0

Remarks

This property specifies whether the struct should force nonintersecting operations against a single file or whole cache to execute serially, or allow them to execute in parallel.

smNone (0) "No serialization", the component does not serialize anything and leaves this task to the user. The same as smPerFileReadingWritingConcurrent serialization mode.
smGlobal (1) "Global", all events are serialized; it is assumed that the user has one instance of code (e.g., class, component) that is capable of handling one request at a time.
smPerFileAllOperations (2) "Per-file, all operations", all operations on a single file are serialized; however, operations with different files may be concurrent.
smPerFileReadingWritingConcurrent (3)(default)"Per-file, reading and writing concurrent", reading and writing to a single file may be concurrent, but access to different ranges is serialized.
smPerFileReadingConcurrent (4) "Per-file, reading concurrent", reading of different ranges of the same file may be concurrent, while writing of different blocks of the file will be serialized.

Note: This property cannot be changed when active is true.

Data Type

i32

stats_cache_size Property (CBCache Struct)

This property contains the current size of the cache.

Syntax

fn stats_cache_size(&self ) -> Result<i64, CBFSConnectError> 

Default Value

0

Remarks

This property contains the current size of the cache.

This property reflects the current size, in bytes, of the file cache.

Properties related to cache statistics are refreshed periodically based on the interval specified by the StatsRefreshInterval configuration setting. Applications that need fresher data can either decrease the update refresh, or call the refresh_statistics method to force an immediate refresh.

Note: This property returns a valid value only when active is true.

This property is read-only.

Data Type

i64

stats_current_file_id Property (CBCache Struct)

This property contains the file currently being read or written by the cache.

Syntax

fn stats_current_file_id(&self ) -> Result<String, CBFSConnectError> 

Default Value

String::default()

Remarks

This property contains the file currently being read or written by the cache.

When stats_current_operation is CACHE_OP_READ or CACHE_OP_WRITE, this property will reflect the Id of the file being read or written. Otherwise, it will return an empty string.

Properties related to cache statistics are refreshed periodically based on the interval specified by the StatsRefreshInterval configuration setting. Applications that need fresher data can either decrease the update refresh, or call the refresh_statistics method to force an immediate refresh.

Note: This property returns a valid value only when active is true.

This property is read-only.

Data Type

String

stats_current_operation Property (CBCache Struct)

This property contains the operation currently being performed by the cache.

Syntax

fn stats_current_operation(&self ) -> Result<i32, CBFSConnectError> 

Default Value

0

Remarks

This property contains the operation currently being performed by the cache.

This property reflects the operation currently being performed by the cache. It will be one of the following values:

CACHE_OP_IDLE0The cache is idle.

CACHE_OP_CLEANUP2Cache cleanup is being performed.

CACHE_OP_COMPACT3The cache's storage file is being compacted.

CACHE_OP_READ4The cache is reading some file's data.

CACHE_OP_WRITE5The cache is writing some file's data.

Properties related to cache statistics are refreshed periodically based on the interval specified by the StatsRefreshInterval configuration setting. Applications that need fresher data can either decrease the update refresh, or call the refresh_statistics method to force an immediate refresh.

Note: This property returns a valid value only when active is true.

This property is read-only.

Data Type

i32

stats_total_data Property (CBCache Struct)

This property contains the total amount of data present in the cache.

Syntax

fn stats_total_data(&self ) -> Result<i64, CBFSConnectError> 

Default Value

0

Remarks

This property contains the total amount of data present in the cache.

This property reflects the total amount of data, in bytes, currently present in the cache.

Properties related to cache statistics are refreshed periodically based on the interval specified by the StatsRefreshInterval configuration setting. Applications that need fresher data can either decrease the update refresh, or call the refresh_statistics method to force an immediate refresh.

Note: This property returns a valid value only when active is true.

This property is read-only.

Data Type

i64

stats_unflushed_data Property (CBCache Struct)

This property contains the amount of unflushed data present in the cache.

Syntax

fn stats_unflushed_data(&self ) -> Result<i64, CBFSConnectError> 

Default Value

0

Remarks

This property contains the amount of unflushed data present in the cache.

This property reflects the amount of unflushed or modified data, in bytes, currently present in the cache.

Properties related to cache statistics are refreshed periodically based on the interval specified by the StatsRefreshInterval configuration setting. Applications that need fresher data can either decrease the update refresh, or call the refresh_statistics method to force an immediate refresh.

Note: This property returns a valid value only when active is true.

This property is read-only.

Data Type

i64

stats_unflushed_files Property (CBCache Struct)

This property contains the number of unflushed files present in the cache.

Syntax

fn stats_unflushed_files(&self ) -> Result<i64, CBFSConnectError> 

Default Value

0

Remarks

This property contains the number of unflushed files present in the cache.

This property reflects the number of files with unflushed or modified data currently present in the cache.

Properties related to cache statistics are refreshed periodically based on the interval specified by the StatsRefreshInterval configuration setting. Applications that need fresher data can either decrease the update refresh, or call the refresh_statistics method to force an immediate refresh.

Note: This property returns a valid value only when active is true.

This property is read-only.

Data Type

i64

tag Property (CBCache Struct)

This property stores application-defined data specific to a particular instance of the struct.

Syntax

fn tag(&self ) -> Result<i64, CBFSConnectError> 
fn set_tag(&self, value : i64) -> Option<CBFSConnectError>

Default Value

0

Remarks

This property can be used to store data specific to a particular instance of the struct.

Data Type

i64

write_block_size Property (CBCache Struct)

This property includes the block size to use when writing file data to external storage.

Syntax

fn write_block_size(&self ) -> Result<i32, CBFSConnectError> 
fn set_write_block_size(&self, value : i32) -> Option<CBFSConnectError>

Default Value

0

Remarks

This property specifies the block size, in bytes, that the struct should use when writing data to external storage via the on_write_data event.

Note: In some cases (e.g., when writing the last part of a file), the amount of data being written may be less than the value specified by this property.

Applications should always set this property to a reasonable value (or use the default value), even if the writing_capabilities property specifies that the external storage only supports whole-file writing.

The property may be overridden by the corresponding parameter of the file_open and file_set_size methods.

Changing this property causes the BlockSize configuration setting's value to be recalculated.

Note: This property cannot be changed when active is true.

Data Type

i32

writing_capabilities Property (CBCache Struct)

This property includes the writing capabilities supported by the external storage.

Syntax

fn writing_capabilities(&self ) -> Result<i32, CBFSConnectError> 
fn set_writing_capabilities(&self, value : i32) -> Option<CBFSConnectError>

Default Value

0

Remarks

This property specifies any and all behaviors of the external storage that are relevant when writing data to it. The struct will automatically alter its behavior based on this property's "description" of how the external storage is able to write file data.

This property should be set by ORing together zero or more of the flags defined as follows. The flags are grouped by name to specify the operations to which they apply.

Flag Group Description
Position Flags with POS in the name describe where read and writes can occur from.
Size Flags with SIZE in the name describe the sizes of read and writes the external data source supports.
Write Flags with WRITE in the name describe flags that are specific to write operations.
Supplemental Flags with SUPPL in the name describe flags that are used to further specify the expectations of the external data source.

Reading and Writing Capability Flags (Position Related)

RWCAP_POS_SEQUENTIAL_FROM_BOF0x00000001No random access allowed; read/write operations must start at the beginning of a file.

When this flag is used in writing capabilities, the struct can initiate reading of missing data before writing the changes to build the complete dataset, which is required for correct write operations.

RWCAP_POS_BLOCK_MULTIPLE0x00000004Reading/writing is possible at positions that are multiple of the corresponding block size.

The read and write block sizes are specified by the read_block_size and write_block_size properties . When this flag is used in writing capabilities, the struct can initiate reading of missing data before writing the changes to build the complete dataset, which is required for correct write operations.

RWCAP_POS_RANDOM0x00000008Reading/writing is possible at any position.

When this flag is used, other flags can still alter the positions at which reading/writing are possible.

RWCAP_POS_SUPPL_ONLY_WITHIN_FILE0x00000010File position must remain in the range: 0 <= FilePos < FileSize

Reading and Writing Capability Flags (Size Related)

RWCAP_SIZE_WHOLE_FILE0x00000100Only whole-file reads/writes are possible; partial reads/writes are not supported.

Note:

  • The read_block_size and write_block_size properties should still be set to reasonable values when using this flag.
  • Use one of the other RWCAP_SIZE_* flags instead of this one if the external storage supports reading subsets of the file.
When this flag is used in writing capabilities, the struct can initiate reading of missing data before writing the changes to build the complete dataset, which is required for correct write operations.

RWCAP_SIZE_FIXED_BLOCKS_WITH_TAIL0x00000200Reads/writes must be done in blocks of a fixed size, except for the last block, which may be of any size.

When this flag is used in writing capabilities, the struct can initiate reading of missing data before writing the changes to build the complete dataset, which is required for correct write operations.

RWCAP_SIZE_FIXED_BLOCKS_NO_TAIL0x00000400Reads/writes must be done in blocks of a fixed size, including the last block.

Note: Real file sizes, if needed, must be stored elsewhere when using the cache with an external storage medium that has this characteristic.

When this flag is used in writing capabilities, the struct can initiate reading of missing data before writing the changes to build the complete dataset, which is required for correct write operations.

RWCAP_SIZE_ANY0x00000800Reads/writes may be done in blocks of any size.

Reading and Writing Capability Flags (Write Related)

RWCAP_WRITE_APPEND_ONLY0x00000002Append only; write operations must start at the end of a file.

To overwrite a file, it must first be truncated, and then written to. (Truncation behavior is defined by the corresponding flags.)

RWCAP_WRITE_SUPPL_NOT_BEYOND_EOF0x00000020File position remain in the range: 0 <= FilePos <= FileSize

When writing, appending to the end of the file is supported, but writing at positions past the end of the file is not.

RWCAP_WRITE_TRUNCATES_FILE0x00001000When writes occur, the last data written becomes the new end of the file.

Any overwritten data, and any data previously present after the written range, are lost.

RWCAP_WRITE_KEEPS_FILESIZE0x00002000Normal writing behavior (i.e., writes do not alter a file's size, except possibly to expand it).

RWCAP_WRITE_NOT_BEYOND_EOF0x00004000Writes may not extend past the end of a file's current size (i.e., cannot cause a file to grow).

Applications may still adjust the file size beforehand.

Note: This property cannot be changed when active is true.

Data Type

i32

cancel_cleanup Method (CBCache Struct)

This method cancels a background cleanup operation, if necessary.

Syntax

fn cancel_cleanup(&self) -> Option<CBFSConnectError>

Remarks

This method cancels any cleanup operation currently being performed in the background. If no such operation is running, this method does nothing.

check_and_repair Method (CBCache Struct)

This method checks a cache vault's consistency and repairs it as necessary.

Syntax

fn check_and_repair(&self, encryption_password : &String, flags : i32) -> Option<CBFSConnectError>

Remarks

This method checks the consistency of a cache vault and attempts to repair it as necessary. Please refer to the Cache Corruption topic for more information.

Applications should call this method if a vault has become corrupted (if a cache operation fails with a ERROR_INTERNAL_VAULT_CORRUPTED error). Be sure to make a vault backup before calling this method, as its repair efforts may cause data loss in cases of severe corruption.

The Flags parameter is used to specify additional options and should be set by OR-ing together zero or more of the following flags:

CACHE_CHECK_NO_RECREATE_VAULT0x00000000If the vault is damaged beyond repair, report an error.

When this flag is used, the check_and_repair will return an error if the vault could not be repaired.

CACHE_CHECK_RECREATE_VAULT0x00000001If the vault is damaged beyond repair, recreate the vault automatically.

When this flag is used, the check_and_repair will delete the damaged vault and create a new one instead.

Note: This method cannot be called when active is true, and it cannot be called within events.

clear Method (CBCache Struct)

This method removes files from the cache.

Syntax

fn clear(&self, remove_orphans : bool, remove_locals : bool) -> Option<CBFSConnectError>

Remarks

This method removes all files from the cache that are fully flushed and currently closed. Depending on the value passed for RemoveOrphans and RemoveLocals, Orphan Files and/or Local Files also may be removed as well.

The operation is performed synchronously, so this method returns once all applicable files have been removed. During the operation, the on_progress event will fire periodically to indicate progress.

close_cache Method (CBCache Struct)

This method closes the cache.

Syntax

fn close_cache(&self, flush_action : i32, purge_action : i32) -> Option<CBFSConnectError>

Remarks

This method closes the cache, optionally performing file flushing and purging operations before doing so.

The FlushAction parameter specifies what kind of flushing to perform, if any. It must be one of the following values:

FLUSH_DELAYED0Flush as usual, taking into account any specified delay.

The flush_after_close_delay property specifies the delay. Passing this value to file_close or file_close_ex will cause the method to return immediately; flushing is performed in the background. Passing this value to close_cache has no effect (i.e., the cache is not flushed before being closed).

FLUSH_NONE1Do not flush anything.

FLUSH_IMMEDIATE2Flush immediately.

Passing this value to file_close, file_close_ex, and close_cache will cause the method to return only after all flushing operations are complete.

The PurgeAction parameter specifies what kind of purging to perform, if any. It must be one of the following values:

PURGE_DELAYED0Purge as usual, taking into account any specified delay.

The purge_after_close_delay property specifies the delay. Passing this value to file_close or file_close_ex will cause the method to return immediately; purging is performed in the background. Passing this value to close_cache has no effect; the cache is not purged before being closed.

PURGE_NONE1Do not purge anything.

PURGE_IMMEDIATE2Purge immediately.

Passing this value to file_close, file_close_ex, or close_cache will cause the method to return only after all purging operations are complete.

close_enumeration Method (CBCache Struct)

This method closes the given file enumeration.

Syntax

fn close_enumeration(&self, enumeration_handle : i64) -> Option<CBFSConnectError>

Remarks

This method closes the file enumeration identified by EnumerationHandle and releases any associated resources.

config Method (CBCache Struct)

Sets or retrieves a configuration setting.

Syntax

fn config(&self, configuration_string : &String) ->  Result<String, CBFSConnectError>

Remarks

config is a generic method available in every struct. It is used to set and retrieve configuration settings for the struct.

These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the struct, access to these internal properties is provided through the config method.

To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.

delete_cache Method (CBCache Struct)

This method deletes the cache completely.

Syntax

fn delete_cache(&self) -> Option<CBFSConnectError>

Remarks

This method deletes the cache specified by the cache_file property completely, removing its storage file from the directory specified by the cache_directory property. If the cache is currently open, it is closed first.

enumerate_cached_files Method (CBCache Struct)

This method enumerates the files in the cache.

Syntax

fn enumerate_cached_files(&self, enumeration_mode : i32) ->  Result<i64, CBFSConnectError>

Remarks

This method initiates a enumeration operation for cached files that match the specified EnunmerationMode, which must be take of the following values:

ENUM_MODE_ALL0Enumerate all files.

ENUM_MODE_CHANGED1Enumerate files with changed blocks.

ENUM_MODE_UNCHANGED2Enumerate files with no changed blocks.

ENUM_MODE_LOCAL4Enumerate local files.

Refer to the Local Files topic for more information.

ENUM_MODE_ORPHAN8Enumerate orphan files.

Refer to the Orphan Files topic for more information.

ENUM_MODE_PINNED16Enumerate pinned files.

This method returns a handle that can be passed to the get_next_enumerated_file method to retrieve the results of the enumeration. If no matching files are found, -1 is returned instead.

When an application is finished enumerating files, it must call the close_enumeration method to release the associated resources.

file_change_id Method (CBCache Struct)

This method changes the Id of a cached file.

Syntax

fn file_change_id(&self, file_id : &String, new_file_id : &String) -> Option<CBFSConnectError>

Remarks

This method changes the Id of the cached file identified by FileId to NewFileId. Applications that use file paths as Ids may need to use this method if a path element is renamed.

This method fails with an error if no file with the specified FileId is present in the cache, or if another file is already present in the cache with NewFileId.

file_close Method (CBCache Struct)

This method closes a cached file.

Syntax

fn file_close(&self, file_id : &String) -> Option<CBFSConnectError>

Remarks

This method closes the cached file identified by FileId, performing any of the flushing and/or purging operations specified by the struct's other properties. (To override the configured flushing and purging behaviors, use the file_close_ex method instead.)

This method returns immediately, and any flushing and/or purging operations are performed in the background.

file_close_ex Method (CBCache Struct)

This method closes a cached file, specifying flushing and purging behaviors explicitly.

Syntax

fn file_close_ex(&self, file_id : &String, flush_action : i32, purge_action : i32) -> Option<CBFSConnectError>

Remarks

This method closes the cached file identified by FileId, performing any flushing and/or purging operations specified by the FlushAction and PurgeAction parameters.

The FlushAction parameter must be passed by one of the following values:

FLUSH_DELAYED0Flush as usual, taking into account any specified delay.

The flush_after_close_delay property specifies the delay. Passing this value to file_close or file_close_ex will cause the method to return immediately; flushing is performed in the background. Passing this value to close_cache has no effect (i.e., the cache is not flushed before being closed).

FLUSH_NONE1Do not flush anything.

FLUSH_IMMEDIATE2Flush immediately.

Passing this value to file_close, file_close_ex, and close_cache will cause the method to return only after all flushing operations are complete.

Note: Passing FLUSH_NONE will cause all background reading and writing threads for the file (if any) to be stopped.

The PurgeAction parameter must be passed by one of the following values:

PURGE_DELAYED0Purge as usual, taking into account any specified delay.

The purge_after_close_delay property specifies the delay. Passing this value to file_close or file_close_ex will cause the method to return immediately; purging is performed in the background. Passing this value to close_cache has no effect; the cache is not purged before being closed.

PURGE_NONE1Do not purge anything.

PURGE_IMMEDIATE2Purge immediately.

Passing this value to file_close, file_close_ex, or close_cache will cause the method to return only after all purging operations are complete.

This method returns immediately, and any flushing and/or purging operations are performed in the background.

file_delete Method (CBCache Struct)

This method deletes a file from the cache.

Syntax

fn file_delete(&self, file_id : &String) -> Option<CBFSConnectError>

Remarks

This method deletes the cached file identified by FileId, removing all of its data from the cache. If the specified file is currently open, it is closed first.

Note: The specified file is not flushed to external storage before being deleted; any unflushed data will be lost.

file_exists Method (CBCache Struct)

This method checks if a file with the given Id is present in the cache.

Syntax

fn file_exists(&self, file_id : &String) ->  Result<bool, CBFSConnectError>

Remarks

This method checks to see whether a file with the specified FileId is present in the cache; returning true if so or false otherwise.

file_flush Method (CBCache Struct)

This method flushes the specified file's modified blocks out to external storage.

Syntax

fn file_flush(&self, file_id : &String, flush_mode : i32, delay : i32, file_context : usize) ->  Result<i32, CBFSConnectError>

Remarks

This method flushes any modified data blocks for the file specified by FileId out to external storage via the on_write_data event (and possibly, the on_read_data event, if the cache is forced to retrieve data from external storage before writing it back). The FlushMode parameter specifies what kind of flushing should be performed. It must take one of the following values:

FLUSH_MODE_SYNC0Flush file data synchronously, blocking until finished.

FLUSH_MODE_ASYNC1Flush file data in the background; do not wait until the flush operation completes.

FLUSH_MODE_TEST2Check to see if file data exists and needs to be flushed, but do not actually flush anything.

The Delay parameter may be passed a non-zero number of seconds to delay the flushing operation.

The FileContext parameter may be passed any application-defined value. If the flushing operation causes the file to be opened, the specified value will be passed through to the on_write_data and on_read_data events' corresponding parameter. (If the file is already open, the value passed to file_open takes precedence).

This method will return one of the following values:

FLUSH_RESULT_NOTHING0The file has no data that need flushing.

FLUSH_RESULT_DIRTY1Data in the file need flushing, but no flush operation is running yet.

FLUSH_RESULT_RUNNING2Data in the file are in the process of being flushed.

FLUSH_RESULT_SUCCESS3Data in the file have been flushed successfully.

file_get_pinned Method (CBCache Struct)

This method returns the pinned state of a cached file.

Syntax

fn file_get_pinned(&self, file_id : &String) ->  Result<bool, CBFSConnectError>

Remarks

This method indicates whether the cached file identified by FileId is pinned (or reports an error if no such file is present in the cache).

Pinned files are the files whose data are not purged automatically. If you need to remove the local data of a pinned file, use the file_purge method.

file_get_size Method (CBCache Struct)

This method gets the "real size" of a cached file.

Syntax

fn file_get_size(&self, file_id : &String) ->  Result<i64, CBFSConnectError>

Remarks

This method returns the application-reported File Sizes for the cached file identified by FileId (or reports an error if no such file is present in the cache).

Note: The size value returned by this method is the one previously set by the application through the file_open or file_set_size method; it does not necessarily correspond to the actual amount of data present in the cache for the file.

file_get_status Method (CBCache Struct)

This method gets the status of a cached file.

Syntax

fn file_get_status(&self, file_id : &String, status_kind : i32) ->  Result<bool, CBFSConnectError>

Remarks

This method returns the status of the cached file identified by FileId (or reports an error if no such file is present in the cache). StatusKind must be one of the following:

FILE_STATUS_CHANGED1Retrieves the value of the Changed state of the file.

FILE_STATUS_UNCHANGED2Retrieves the value of the Unchanged state of the file.

FILE_STATUS_LOCAL3Retrieves the value that indicates whether the file is Local.

Refer to the Local Files topic for more information.

FILE_STATUS_ORPHAN4Retrieves the value that indicates whether the file is Orphan.

Refer to the Orphan Files topic for more information.

FILE_STATUS_OPEN5Retrieves the value of the Open state of the file.

file_open Method (CBCache Struct)

This method opens the specified cached file, creating it if necessary.

Syntax

fn file_open(&self, file_id : &String, real_file_size : i64, prefetch_size : i64, file_context : usize) -> Option<CBFSConnectError>

Remarks

This method opens the cached file identified by FileId, creating it if necessary.

The RealFileSize parameter informs the cache of the File Sizes (in bytes) of the real file (i.e., the one in external storage); this size can be changed later using the file_set_size method. For existing cached files, -1 may be passed to instruct the cache to use the previously set real file size instead.

The PrefetchSize parameter specifies how many bytes of data the cache should prefetch, from external storage, for the file via the on_read_data event (which will fire on a background thread). Pass PREFETCH_ALL to prefetch the entire fire, or PREFETCH_NOTHING to prefetch none of it.

The FileContext may be passed to any application-defined value; this value will then be passed through to any on_read_data and on_write_data events fired for the file.

file_open_ex Method (CBCache Struct)

This method opens the specified cached file, creating it if necessary.

Syntax

fn file_open_ex(&self, file_id : &String, real_file_size : i64, is_local : bool, read_block_size : i32, write_block_size : i32, prefetch_size : i64, file_context : usize) -> Option<CBFSConnectError>

Remarks

This method opens the cached file identified by FileId, creating it if necessary.

The RealFileSize parameter informs the cache of the File Sizes (in bytes) of the real file (i.e., the one in external storage); this size can be changed later using the file_set_size method. For existing cached files, -1 may be passed to instruct the cache to use the previously set real file size instead.

The IsLocal parameter specifies whether the file is a local to the cache and does not exist in external storage; refer to the Local Files topic for more information.

ReadBlockSize and WriteBlockSize parameters make it possible for the application to configure the size of the block for reading and writing, respectively, thus overriding the values specified in the read_block_size and write_block_size properties for a specific file. Set the parameter to 0 to make the struct use the value from the corresponding property. The values of the parameters will be used when reading_capabilities or writing_capabilities properties indicate that reading or writing should be performed in blocks of a specific size (or when the whole file should be read or written using sequential block operations).

The PrefetchSize parameter specifies how many bytes of data the cache should prefetch, from external storage, for the file through the on_read_data event (which will fire on a background thread). Pass PREFETCH_ALL to prefetch the entire fire, or PREFETCH_NOTHING to prefetch none of it. This parameter is ignored if IsLocal is true.

The FileContext may be passed to any application-defined value; this value will then be passed through to any on_read_data and on_write_data events fired for the file.

file_purge Method (CBCache Struct)

This method purges unmodified data from the cache.

Syntax

fn file_purge(&self, file_id : &String) -> Option<CBFSConnectError>

Remarks

This method removes unmodified data from the cache.

Use file_purge with pinned files to free space or after the pinned attribute has been removed and you need to remove the data immediately.

file_read Method (CBCache Struct)

This method reads the specified part of a cached file.

Syntax

fn file_read(&self, file_id : &String, position : i64, buffer : &[u8], index : i32, count : i32) ->  Result<bool, CBFSConnectError>

Remarks

This method reads data from the cached file identified by FileId into the specified Buffer. The cached file must be opened using file_open before it can be read from.

Count bytes of data will be read from the cached file, starting from the specified Position, into the given Buffer. The data are written to Buffer starting at the given Index.

The method returns false if any errors happened during reading and returns true if everything went fine.

file_set_pinned Method (CBCache Struct)

This method sets the pinned state of a cached file.

Syntax

fn file_set_pinned(&self, file_id : &String, pinned : bool) -> Option<CBFSConnectError>

Remarks

This method specifies whether the cached file identified by FileId should be treated as pinned.

Pinned files are the files whose data are not purged automatically. If you need to remove the local data of a pinned file, use the file_purge method.

file_set_size Method (CBCache Struct)

This method sets the "real size" of a cached file.

Syntax

fn file_set_size(&self, file_id : &String, new_size : i64, fetch_missing_data : bool) -> Option<CBFSConnectError>

Remarks

This method changes the "real size" of the cached file identified by FileId to the number of bytes specified by NewSize. The cached file must be opened using file_open before its real size can be changed.

ReadBlockSize and WriteBlockSize parameters make it possible for the application to configure the size of the block for reading and writing, respectively, thus overriding the values specified in the read_block_size and write_block_size properties for a specific file. Set the parameter to 0 to make the struct use the value from the corresponding property. The values of the parameters will be used when reading_capabilities or writing_capabilities properties indicate that reading or writing should be performed in blocks of a specific size (or when the whole file should be read or written using sequential block operations).

The FetchMissingData parameter controls how the cache initializes new file space in cases in which the file's real size is increased. If FetchMissingData is true, the new file space is filled with real data fetched from external storage. Otherwise, the new file space is marked as zero-filled (although no actual data writing occurs).

file_set_size_ex Method (CBCache Struct)

This method sets the "real size" of a cached file.

Syntax

fn file_set_size_ex(&self, file_id : &String, new_size : i64, read_block_size : i32, write_block_size : i32, fetch_missing_data : bool) -> Option<CBFSConnectError>

Remarks

This method changes the "real size" of the cached file identified by FileId to the number of bytes specified by NewSize. The cached file must be opened using file_open before its real size can be changed.

ReadBlockSize and WriteBlockSize parameters make it possible for the application to configure the size of the block for reading and writing, respectively, thus overriding the values specified in the read_block_size and write_block_size properties for a specific file. Set the parameter to 0 to make the struct use the value from the corresponding property. The values of the parameters will be used when reading_capabilities or writing_capabilities properties indicate that reading or writing should be performed in blocks of a specific size (or when the whole file should be read or written using sequential block operations).

The FetchMissingData parameter controls how the cache initializes new file space in cases in which the file's real size is increased. If FetchMissingData is true, the new file space is filled with real data fetched from external storage. Otherwise, the new file space is marked as zero-filled (although no actual data writing occurs).

file_tag_delete Method (CBCache Struct)

This method deletes a file tag.

Syntax

fn file_tag_delete(&self, file_id : &String, tag_id : i32) -> Option<CBFSConnectError>

Remarks

This method deletes the file tag identified by TagId from the cached file specified by FileId.

Please refer to the File Tags topic for more information.

Note: This method can be called only when active is true, and it cannot be called within events.

file_tag_exists Method (CBCache Struct)

This method checks whether or not a file has a specific tag associated with it.

Syntax

fn file_tag_exists(&self, file_id : &String, tag_id : i32) ->  Result<bool, CBFSConnectError>

Remarks

This method returns true if a file identified by FileId has an associated tag identified by TagId; otherwise, it returns false.

The value passed for TagId must be in the range from 0x0001 to 0xCFFF (inclusive).

Please refer to the File Tags topic for more information.

Note: This method can be called only when active is true, and it cannot be called within events.

file_tag_get Method (CBCache Struct)

This method retrieves the binary data held by a file tag attached to the specified cached file.

Syntax

fn file_tag_get(&self, file_id : &String, tag_id : i32) ->  Result<Vec<u8>, CBFSConnectError>

Remarks

This method retrieves the binary data stored in a file tag, identified by TagId attached to the file identified by FileId. If a file tag with the specified TagId is not attached to the specified file, this method .

The value passed for TagId must be in the range from 0x0001 to 0xCFFF (inclusive).

Please refer to the File Tags topic for more information.

Note: This method can be called only when active is true, and it cannot be called within events.

file_tag_get_size Method (CBCache Struct)

This method retrieves the size of a file tag attached to the specified cached file.

Syntax

fn file_tag_get_size(&self, file_id : &String, tag_id : i32) ->  Result<i32, CBFSConnectError>

Remarks

This method retrieves the size of the binary data stored in a file tag, identified by TagId, attached to the cached file identified by FileId. If a file tag with the specified TagId is not attached to the specified file, this method returns 0 as the tag size.

The value passed for TagId must be in the range from 0x0001 to 0xCFFF (inclusive).

Please refer to the File Tags topic for more information.

Note: This method can be called only when active is true.

file_tag_set Method (CBCache Struct)

This method attaches a file tag with binary data to the specified cached file.

Syntax

fn file_tag_set(&self, file_id : &String, tag_id : i32, data : &[u8]) -> Option<CBFSConnectError>

Remarks

This method attaches a file tag with binary data to the cached file identified by FileId using the specified TagId. If a file tag with the specified TagId is already attached to the specified file, it is replaced.

The value passed for TagId must be in the range from 0x0001 to 0xCFFF (inclusive).

The Data parameter specifies the raw binary data to store in the file tag; it may be up to 65531 bytes in length.

Please refer to the File Tags topic for more information.

Note: This method can be called only when active is true, and it cannot be called within events.

file_touch Method (CBCache Struct)

This method touches a range of data in a cached file.

Syntax

fn file_touch(&self, file_id : &String, position : i64, count : i32, flush : bool) -> Option<CBFSConnectError>

Remarks

This method touches a range of data in the cached file identified by FileId, thereby marking it as changed and in need of flushing. The range of data to be touched starts at the specified Position and extends for Count bytes.

The cache will automatically attempt to read in any unavailable data in the touched range via on_read_data, and then will write out all data in the touched range via on_write_data. If the Flush parameter is true, these operations will take place synchronously and block return of this method; otherwise, they will take place in the background and this method will return immediately.

file_write Method (CBCache Struct)

This method writes the specified part of a cached file.

Syntax

fn file_write(&self, file_id : &String, position : i64, buffer : &[u8], index : i32, count : i32) ->  Result<bool, CBFSConnectError>

Remarks

This method writes data to the cached file identified by FileId from the specified Buffer. The cached file must be opened using file_open before it can be written to.

Count bytes of data will be read from the given Buffer, starting at the given Index, and written into the cached file. The data are written to the cached file starting at the given Position.

If any amount of data is written beyond the known file size, such writing causes the file to grow unless the RWCAP_WRITE_NOT_BEYOND_EOF flag is specified. When the file grows, the known file size value for the file is updated and all the data are eventually flushed (written) to the external storage via the on_write_data event. The RWCAP_WRITE_NOT_BEYOND_EOF flag indicates that no writing should occur beyond the known file size, thus preventing the file from growth.

The method returns false if any errors happened during writing and returns true if everything went fine.

get_next_enumerated_file Method (CBCache Struct)

This method returns the next file in the list of enumeration results.

Syntax

fn get_next_enumerated_file(&self, enumeration_handle : i64) ->  Result<String, CBFSConnectError>

Remarks

This method returns the Id of the next file in the list of enumeration results identified by the EnumerationHandle parameter. If the list does not have any more files, an empty string is returned.

When an empty string is returned because the end of the list has been reached, the struct will close the enumeration automatically by calling close_enumeration. If the application finishes enumeration without reaching the end of the list, it must call the close_enumeration method to release any associated resources.

open_cache Method (CBCache Struct)

This method opens the cache.

Syntax

fn open_cache(&self, encryption_password : &String, case_sensitive : bool) -> Option<CBFSConnectError>

Remarks

This method opens the cache specified by the cache_file property; creating a storage file for it in the directory specified by the cache_directory property, if necessary.

To encrypt the cache, pass a nonempty string for the EncryptionPassword parameter the first time it is created. The same value will need to be passed any time the cache is opened again in the future.

If the StoreDataInFiles configuration setting is enabled, encryption affects only the main cache storage file and not the files that are used to store individual files' data.

The CaseSensitive parameter specifies whether the cache should treat its File Ids as case-sensitive or case-insensitive.

refresh_statistics Method (CBCache Struct)

This method forces a refresh of the cache's statistics.

Syntax

fn refresh_statistics(&self) -> Option<CBFSConnectError>

Remarks

This method forces the cache to immediately refresh its statistics. The refreshed statistics will be reported through the on_status event and will be used to update the stats property.

This method needs to be called only if the applications needs to update the cache's statistics sooner than the end of the current StatsRefreshInterval.

reset_error_state Method (CBCache Struct)

This method resets any outstanding errors for a file or external storage.

Syntax

fn reset_error_state(&self, file_id : &String) -> Option<CBFSConnectError>

Remarks

If FileId is specified, this method resets any outstanding file errors, related to the cached file identified by FileId, previously reported via on_read_data and/or on_write_data events, thus allowing operations on the file to continue. If there are no outstanding errors for the specified file, this method does nothing.

If FileId is empty, this method resets any outstanding external-storage-related error previously reported via a on_read_data or on_write_data event, thus allowing external I/O operations to continue. If there are no outstanding external storage errors, this method does nothing.

start_cleanup Method (CBCache Struct)

This method starts a background cleanup operation to remove unused files from the cache.

Syntax

fn start_cleanup(&self, max_age : i32) -> Option<CBFSConnectError>

Remarks

This method starts a cleanup operation to remove unused files from the cache. Files used earlier than MaxAge hours ago will be removed (passing 0 will cause all files to be removed).

The cleanup operation is performed asynchronously in a background thread, so this method returns immediately. To cancel a cleanup operation, use the cancel_cleanup method.

on_before_flush Event (CBCache Struct)

This event fires to report the start of the asynchronous file flush procedure.

Syntax

// CBCacheBeforeFlushEventArgs carries the CBCache BeforeFlush event's parameters.
pub struct CBCacheBeforeFlushEventArgs {
  fn file_id(&self) -> &String
  fn file_context(&self) -> usize
  fn last_use_time(&self) -> &chrono::DateTime<Utc>
  fn postpone_time(&self) -> i32
  fn set_postpone_time(&self, value : i32)
}

// CBCacheBeforeFlushEvent defines the signature of the CBCache BeforeFlush event's handler function.
pub trait CBCacheBeforeFlushEvent {
  fn on_before_flush(&self, sender : CBCache, e : &mut CBCacheBeforeFlushEventArgs);
}

impl <'a> CBCache<'a> {
  pub fn on_before_flush(&self) -> &'a dyn CBCacheBeforeFlushEvent;
  pub fn set_on_before_flush(&mut self, value : &'a dyn CBCacheBeforeFlushEvent);
  ...
}

Remarks

This event fires when the asynchronous file flush procedure starts for the cached file identified by FileId. This event does not fire if the flush procedure is initiated by the application using file_flush, file_close, or file_close_ex methods.

Note: This event will fire in the context of a dedicated worker thread that performs cache maintenance. Keep handling of this event as quick as possible.

Use the PostponeTime parameter to specify time in seconds to postpone automatic flush operation for this file.

on_before_purge Event (CBCache Struct)

This event fires to report the start of the asynchronous file purge procedure.

Syntax

// CBCacheBeforePurgeEventArgs carries the CBCache BeforePurge event's parameters.
pub struct CBCacheBeforePurgeEventArgs {
  fn file_id(&self) -> &String
  fn file_context(&self) -> usize
  fn last_use_time(&self) -> &chrono::DateTime<Utc>
  fn postpone_time(&self) -> i32
  fn set_postpone_time(&self, value : i32)
}

// CBCacheBeforePurgeEvent defines the signature of the CBCache BeforePurge event's handler function.
pub trait CBCacheBeforePurgeEvent {
  fn on_before_purge(&self, sender : CBCache, e : &mut CBCacheBeforePurgeEventArgs);
}

impl <'a> CBCache<'a> {
  pub fn on_before_purge(&self) -> &'a dyn CBCacheBeforePurgeEvent;
  pub fn set_on_before_purge(&mut self, value : &'a dyn CBCacheBeforePurgeEvent);
  ...
}

Remarks

This event fires when the asynchronous file purge procedure starts for the cached file identified by FileId. This event does not fire if the purge procedure is initiated by the application using the file_flush, file_close, or file_close_ex methods.

Note: This event will fire in the context of a dedicated worker thread that performs cache maintenance. Keep handling of this event as quick as possible.

Use the PostponeTime parameter to specify time in seconds to postpone automatic purge operation for this file.

on_end_cleanup Event (CBCache Struct)

This event fires to report the beginning of the asynchronous cleanup procedure.

Syntax

// CBCacheEndCleanupEventArgs carries the CBCache EndCleanup event's parameters.
pub struct CBCacheEndCleanupEventArgs {
}

// CBCacheEndCleanupEvent defines the signature of the CBCache EndCleanup event's handler function.
pub trait CBCacheEndCleanupEvent {
  fn on_end_cleanup(&self, sender : CBCache, e : &mut CBCacheEndCleanupEventArgs);
}

impl <'a> CBCache<'a> {
  pub fn on_end_cleanup(&self) -> &'a dyn CBCacheEndCleanupEvent;
  pub fn set_on_end_cleanup(&mut self, value : &'a dyn CBCacheEndCleanupEvent);
  ...
}

Remarks

This event fires when the asynchronous cleanup procedure ends.

Note: This event will fire in the context of a dedicated worker thread that performs cache maintenance. Keep handling of this event as quick as possible.

on_error Event (CBCache Struct)

This event fires if an unhandled error occurs during an event.

Syntax

// CBCacheErrorEventArgs carries the CBCache Error event's parameters.
pub struct CBCacheErrorEventArgs {
  fn error_code(&self) -> i32
  fn description(&self) -> &String
}

// CBCacheErrorEvent defines the signature of the CBCache Error event's handler function.
pub trait CBCacheErrorEvent {
  fn on_error(&self, sender : CBCache, e : &mut CBCacheErrorEventArgs);
}

impl <'a> CBCache<'a> {
  pub fn on_error(&self) -> &'a dyn CBCacheErrorEvent;
  pub fn set_on_error(&mut self, value : &'a dyn CBCacheErrorEvent);
  ...
}

Remarks

This event fires if an unhandled error occurs during another event. Developers can use this information to track down unhandled errors in an application's event handlers.

IMPORTANT: Not everything is possible or allowed in the event handlers. Please see the Event Handling topic for details.

on_log Event (CBCache Struct)

This log reports events that occur in the struct.

Syntax

// CBCacheLogEventArgs carries the CBCache Log event's parameters.
pub struct CBCacheLogEventArgs {
  fn level(&self) -> i32
  fn message(&self) -> &String
}

// CBCacheLogEvent defines the signature of the CBCache Log event's handler function.
pub trait CBCacheLogEvent {
  fn on_log(&self, sender : CBCache, e : &mut CBCacheLogEventArgs);
}

impl <'a> CBCache<'a> {
  pub fn on_log(&self) -> &'a dyn CBCacheLogEvent;
  pub fn set_on_log(&mut self, value : &'a dyn CBCacheLogEvent);
  ...
}

Remarks

This event fires when the struct needs to notify an application or developers about something that happened internally. The verbosity is controlled by the LogLevel setting.

LogLevel indicates the level of the message. Possible values are as follows:

0 (None) No information is logged.
1 (Errors) Only errors are logged.
2 (Warnings) Errors and warnings are logged.
3 (Information - Default) Errors, warnings, and informational messages are logged.
4 (Debug) Debug data are logged.

Message is the log entry.

Note: This event will fire in the context of a dedicated worker thread. Keep handling of this event as quick as possible.

on_progress Event (CBCache Struct)

This event fires to report the progress of an operation.

Syntax

// CBCacheProgressEventArgs carries the CBCache Progress event's parameters.
pub struct CBCacheProgressEventArgs {
  fn operation(&self) -> i32
  fn current(&self) -> i64
  fn total(&self) -> i64
  fn interrupt(&self) -> bool
  fn set_interrupt(&self, value : bool)
}

// CBCacheProgressEvent defines the signature of the CBCache Progress event's handler function.
pub trait CBCacheProgressEvent {
  fn on_progress(&self, sender : CBCache, e : &mut CBCacheProgressEventArgs);
}

impl <'a> CBCache<'a> {
  pub fn on_progress(&self) -> &'a dyn CBCacheProgressEvent;
  pub fn set_on_progress(&mut self, value : &'a dyn CBCacheProgressEvent);
  ...
}

Remarks

This event fires when the cache wants to report the progress of the operation specified by Operation. Possible values are as follows:

CACHE_PO_CLEANUP1Cache cleanup

The Current and Total parameters specify the number of the item being processed, and the total number of items being processed, respectively. For some operations, these parameters may be 0 or -1.

The Interrupt parameter can be set to true to stop the operation.

on_read_data Event (CBCache Struct)

This event fires when the cache needs to read file data from external storage.

Syntax

// CBCacheReadDataEventArgs carries the CBCache ReadData event's parameters.
pub struct CBCacheReadDataEventArgs {
  fn file_id(&self) -> &String
  fn size(&self) -> i64
  fn position(&self) -> i64
  fn flags(&self) -> i32
  fn buffer(&self) -> *mut u8
  fn bytes_to_read(&self) -> i32
  fn bytes_read(&self) -> i32
  fn set_bytes_read(&self, value : i32)
  fn file_context(&self) -> usize
  fn result_code(&self) -> i32
  fn set_result_code(&self, value : i32)
}

// CBCacheReadDataEvent defines the signature of the CBCache ReadData event's handler function.
pub trait CBCacheReadDataEvent {
  fn on_read_data(&self, sender : CBCache, e : &mut CBCacheReadDataEventArgs);
}

impl <'a> CBCache<'a> {
  pub fn on_read_data(&self) -> &'a dyn CBCacheReadDataEvent;
  pub fn set_on_read_data(&mut self, value : &'a dyn CBCacheReadDataEvent);
  ...
}

Remarks

This event fires when the cache needs to read data for the cached file identified by FileId from an external storage.

The Size parameter reflects the specified file's "real size" as it is currently known by the cache.

The Position parameter reflects the byte offset in the real file (i.e., the one in the external storage) from which the handler should start reading data.

The Flags parameter provides supplementary information about the nature of the request. This parameter, along with the Size and Position parameters, helps the event handler to determine, which part of the file Buffer represents and whether additional on_read_data events should be expected. It will include a combination of one or more of the following flags:

RWEVENT_IN_PROGRESS0x00000001A file's data are being transferred into or out of the cache.

RWEVENT_CANCELED0x00000002A data transfer has been canceled for some reason.

RWEVENT_WHOLE_FILE0x00000004The entire file is being transferred.

RWEVENT_CONTINUOUS_STARTED0x00000010A continuous transfer has started.

RWEVENT_CONTINUOUS_RESTARTED0x00000020A continuous transfer has restarted from the beginning.

RWEVENT_CONTINUOUS_FINISHED0x00000040A continuous transfer is finishing (i.e., the current block is the final one).

RWEVENT_RANDOM_STARTED0x00000100A random-access transfer has started.

RWEVENT_RANDOM_FINISHED0x00000200A random-access transfer is finishing (i.e., the current block is the final one).

RWEVENT_BEFORE_END0x00001000The current transfer will finish before the end of the file.

RWEVENT_TIL_END0x00002000The current transfer will last until the end of the file.

To handle this event property, a handler must read BytesToRead bytes of data from the real file in external storage, starting at the specified Position, into Buffer.

Please see the Buffer Parameters topic for more information on how to work with memory buffer event parameters.

Note: If Flags contains RWEVENT_CANCELED, the transfer is being canceled and no data should be read; the Buffer is not provided and both Position and BytesToRead parameters are set to 0.

When reading is complete, a handler must set BytesRead to reflect the actual number of bytes read from the real file. A handler must not attempt to copy more than BytesToRead bytes of data into Buffer.

The FileContext parameter reflects the application-defined value passed when file_open was called.

The ResultCode parameter will always be 0 when the event is fired. If the event cannot be handled in a "successful" manner for some reason (e.g., a resource is not available, security checks failed), set it to one of the following values to report an appropriate error:

RWRESULT_SUCCESS0x00000000Success.

Returning this code indicates that all data were successfully transferred.

RWRESULT_PARTIAL0x00000080Partial success.

Returning this code indicates that some, but not all, data were successfully transferred. i.e., when BytesRead < BytesToRead (for on_read_data), or BytesWritten < BytesToWrite (for on_write_data).

RWRESULT_RANGE_BEYOND_EOF0x00000081Specified range is beyond the end of the file (EOF).

For the on_read_data event, returning this code indicates to the cache that there is no need to request data beyond (Position + BytesRead), and that the tail should be zeroed instead.

RWRESULT_FILE_MODIFIED_EXTERNALLY0x00000082The specified file's size was modified externally.

Returning this code indicates that the operation was not completed successfully because of this conflicting situation.

RWRESULT_FILE_MODIFIED_LOCALLY0x00000083The requested file's size was modified locally.

RWRESULT_FAILURE0x0000008DThe operation failed for some transient reason.

Returning this code indicates that, even though the current request failed, it is safe to continue sending requests for both the specified file and others. (Other operations may continue.)

RWRESULT_FILE_FAILURE0x0000008EThe operation failed for some external-file-related reason.

Returning this code indicates that some failure related to the external file has occurred, and it is expected that any further requests made against that file will also fail. The struct will not send any more requests for the specified file until the file-specific error is reset as described in Reporting Transfer Errors.

RWRESULT_PERMANENT_FAILURE0x0000008FThe operation failed for some external-storage-related reason.

Returning this code indicates that some failure related to the external storage has occurred, and it is expected that all further requests will also fail. The struct will not send any more requests for any file until the global error is reset as described in Reporting Transfer Errors.

Please refer to the Error Handling topic for more information.

on_start_cleanup Event (CBCache Struct)

This event fires to report the beginning of the asynchronous cleanup procedure.

Syntax

// CBCacheStartCleanupEventArgs carries the CBCache StartCleanup event's parameters.
pub struct CBCacheStartCleanupEventArgs {
}

// CBCacheStartCleanupEvent defines the signature of the CBCache StartCleanup event's handler function.
pub trait CBCacheStartCleanupEvent {
  fn on_start_cleanup(&self, sender : CBCache, e : &mut CBCacheStartCleanupEventArgs);
}

impl <'a> CBCache<'a> {
  pub fn on_start_cleanup(&self) -> &'a dyn CBCacheStartCleanupEvent;
  pub fn set_on_start_cleanup(&mut self, value : &'a dyn CBCacheStartCleanupEvent);
  ...
}

Remarks

This event fires when the asynchronous cleanup procedure starts.

Note: This event will fire in the context of a dedicated worker thread that performs cache maintenance. Keep handling of this event as quick as possible.

on_status Event (CBCache Struct)

This event fires to report the latest cache statistics.

Syntax

// CBCacheStatusEventArgs carries the CBCache Status event's parameters.
pub struct CBCacheStatusEventArgs {
  fn cache_size(&self) -> i64
  fn total_data(&self) -> i64
  fn unflushed_data(&self) -> i64
  fn unflushed_files(&self) -> i32
  fn current_operation(&self) -> i32
  fn current_file_id(&self) -> &String
}

// CBCacheStatusEvent defines the signature of the CBCache Status event's handler function.
pub trait CBCacheStatusEvent {
  fn on_status(&self, sender : CBCache, e : &mut CBCacheStatusEventArgs);
}

impl <'a> CBCache<'a> {
  pub fn on_status(&self) -> &'a dyn CBCacheStatusEvent;
  pub fn set_on_status(&mut self, value : &'a dyn CBCacheStatusEvent);
  ...
}

Remarks

This event fires once every StatsRefreshInterval to provide the application with the latest cache statistics, as well as information about any in-progress cache operation.

The CacheSize parameter reflects the current size of the cache, in bytes.

The TotalData parameter reflects the total amount of data present in the cache, in bytes.

The UnflushedData parameter reflects the amount of unflushed data present in the cache, in bytes.

The UnflushedFiles parameter reflects the number of unflushed files present in the cache.

The CurrentOperation parameter reflects the cache's current operations; it will take one of the following values:

CACHE_OP_IDLE0The cache is idle.

CACHE_OP_CLEANUP2Cache cleanup is being performed.

CACHE_OP_COMPACT3The cache's storage file is being compacted.

CACHE_OP_READ4The cache is reading some file's data.

CACHE_OP_WRITE5The cache is writing some file's data.

When CurrentOperation is CACHE_OP_READ or CACHE_OP_WRITE, the CurrentFileId parameter will reflect the Id of the cached file being processed.

Note: This event can fire in the context of any thread.

on_write_data Event (CBCache Struct)

This event fires when the cache needs to write file data to external storage.

Syntax

// CBCacheWriteDataEventArgs carries the CBCache WriteData event's parameters.
pub struct CBCacheWriteDataEventArgs {
  fn file_id(&self) -> &String
  fn size(&self) -> i64
  fn position(&self) -> i64
  fn flags(&self) -> i32
  fn buffer(&self) -> *mut u8
  fn bytes_to_write(&self) -> i32
  fn bytes_written(&self) -> i32
  fn set_bytes_written(&self, value : i32)
  fn file_context(&self) -> usize
  fn result_code(&self) -> i32
  fn set_result_code(&self, value : i32)
}

// CBCacheWriteDataEvent defines the signature of the CBCache WriteData event's handler function.
pub trait CBCacheWriteDataEvent {
  fn on_write_data(&self, sender : CBCache, e : &mut CBCacheWriteDataEventArgs);
}

impl <'a> CBCache<'a> {
  pub fn on_write_data(&self) -> &'a dyn CBCacheWriteDataEvent;
  pub fn set_on_write_data(&mut self, value : &'a dyn CBCacheWriteDataEvent);
  ...
}

Remarks

This event fires when the cache needs to write data for the cached file identified by FileId to external storage.

The Size parameter reflects the specified file's "real size" as it is currently known by the cache.

The Position parameter reflects the byte offset in the real file (i.e., the one in external storage) at which the application should start writing data.

The Flags parameter provides supplementary information about the nature of the request. This parameter, along with the Size and Position parameters, helps the application to determine which part of the file Buffer represents, and whether additional on_write_data events should be expected. It will include a combination of one or more of the following flags:

RWEVENT_IN_PROGRESS0x00000001A file's data are being transferred into or out of the cache.

RWEVENT_CANCELED0x00000002A data transfer has been canceled for some reason.

RWEVENT_WHOLE_FILE0x00000004The entire file is being transferred.

RWEVENT_CONTINUOUS_STARTED0x00000010A continuous transfer has started.

RWEVENT_CONTINUOUS_RESTARTED0x00000020A continuous transfer has restarted from the beginning.

RWEVENT_CONTINUOUS_FINISHED0x00000040A continuous transfer is finishing (i.e., the current block is the final one).

RWEVENT_RANDOM_STARTED0x00000100A random-access transfer has started.

RWEVENT_RANDOM_FINISHED0x00000200A random-access transfer is finishing (i.e., the current block is the final one).

RWEVENT_BEFORE_END0x00001000The current transfer will finish before the end of the file.

RWEVENT_TIL_END0x00002000The current transfer will last until the end of the file.

To handle this event properly, applications must write BytesToWrite bytes of data from Buffer to the real file in external storage, starting at the specified Position.

Please see the Buffer Parameters topic for more information on how to work with memory buffer event parameters.

Note: If Flags contains RWEVENT_CANCELED, the transfer is being canceled and no data should be written; the Buffer is not provided and both Position and BytesToWrite parameters are set to 0.

When writing is complete, applications must set BytesWritten to reflect the actual number of bytes written to the real file. Applications must not attempt to copy more than BytesToWrite bytes of data from Buffer.

The FileContext parameter reflects the application-defined value passed when file_open was called.

The ResultCode parameter will always be 0 when the event is fired. If the event cannot be handled in a "successful" manner for some reason (e.g., a resource is not available, security checks failed), set it to one of the following values to report an appropriate error:

RWRESULT_SUCCESS0x00000000Success.

Returning this code indicates that all data were successfully transferred.

RWRESULT_PARTIAL0x00000080Partial success.

Returning this code indicates that some, but not all, data were successfully transferred. i.e., when BytesRead < BytesToRead (for on_read_data), or BytesWritten < BytesToWrite (for on_write_data).

RWRESULT_RANGE_BEYOND_EOF0x00000081Specified range is beyond the end of the file (EOF).

For the on_read_data event, returning this code indicates to the cache that there is no need to request data beyond (Position + BytesRead), and that the tail should be zeroed instead.

RWRESULT_FILE_MODIFIED_EXTERNALLY0x00000082The specified file's size was modified externally.

Returning this code indicates that the operation was not completed successfully because of this conflicting situation.

RWRESULT_FILE_MODIFIED_LOCALLY0x00000083The requested file's size was modified locally.

RWRESULT_FAILURE0x0000008DThe operation failed for some transient reason.

Returning this code indicates that, even though the current request failed, it is safe to continue sending requests for both the specified file and others. (Other operations may continue.)

RWRESULT_FILE_FAILURE0x0000008EThe operation failed for some external-file-related reason.

Returning this code indicates that some failure related to the external file has occurred, and it is expected that any further requests made against that file will also fail. The struct will not send any more requests for the specified file until the file-specific error is reset as described in Reporting Transfer Errors.

RWRESULT_PERMANENT_FAILURE0x0000008FThe operation failed for some external-storage-related reason.

Returning this code indicates that some failure related to the external storage has occurred, and it is expected that all further requests will also fail. The struct will not send any more requests for any file until the global error is reset as described in Reporting Transfer Errors.

Please refer to the Error Handling topic for more information.

Config Settings (CBCache Struct)

The struct accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the struct, access to these internal properties is provided through the config method.

CBCache Config Settings

BlockSize:   The size of the block, used to store the data.

This read-only configuration setting returns the size of the block, used by the cache to store and transfer the data. The initial value is 0. It is recalculated depending on the capabilities of the application and the supported size of the reading and writing blocks.

JournalingMode:   Specifies whether the main cache file uses journaling for increased data consistency.

This configuration setting specifies whether the filesystem behind the main cache file should use journaling for metadata and main file data. Possible values are:

VAULT_JM_NONE0No journaling is used.

This mode ensures the fastest operations, but if the application crashes, corruption of the vault is possible.

VAULT_JM_METADATA1Journaling is used only for metadata (filesystem structure and directory contents).

This mode is a balance between speed and reliability.

VAULT_JM_FULL2Journaling is used for both filesystem structure and file data and metadata.

This mode is the slowest but the most reliable option.

LogLevel:   The level of detail that is logged.

This configuration setting controls the level of detail that is logged through the on_log event. Possible values are as follows:

0 (None) No information is logged.
1 (Errors) Only errors are logged.
2 (Warnings) Errors and warnings are logged.
3 (Information - Default) Errors, warnings, and informational messages are logged.
4 (Debug) Debug data are logged.

MaxReaderThreadsPerFile:   The maximum number of reader threads to use to fire events.

This configuration setting specifies the maximum number of reader threads per file the struct may create to fire events when the serialization property is set to smPerFileReadingWritingConcurrent value.

By default, this configuration setting is set to 4 threads per file.

StatsRefreshInterval:   Minimum time period between cache statistics refreshes.

This configuration setting specifies the minimum time period, in milliseconds, between automatic cache statistics refreshes. Each statistics refresh causes the on_status event to fire and updates the values in the stats property.

The statistics refresh interval is intended to prevent excessive user interface changes. Set the value to 0 to disable automatic refresh. The default value is 100 ms.

Note: Applications may call refresh_statistics at any time to explicitly refresh the cache's statistics.

StoreDataInFiles:   Specifies whether file data should be stored in the main cache file or in individual files.

When this configuration setting is disabled (default), the cache stores all data in one file with encryption and compression applied (when they are enabled through the corresponding properties).

When this configuration setting is enabled, the cache stores individual files' data in separate files and uses the main cache file to store various metadata. This option makes the main cache file smaller and opening of the cache file becomes faster. Also, the speed of intensive write operations of large files is increased. The cache in this mode, however, does not provide encryption or compression of file data and journaling of file data does not take place either.

Base Config Settings

BuildInfo:   Information about the product's build.

When queried, this setting will return a string containing information about the product's build.

LicenseInfo:   Information about the current license.

When queried, this setting will return a string containing information about the license this instance of a struct is using. It will return the following information:

  • Product: The product the license is for.
  • Product Key: The key the license was generated from.
  • License Source: Where the license was found (e.g., RuntimeLicense, License File).
  • License Type: The type of license installed (e.g., Royalty Free, Single Server).

Trappable Errors (CBCache Struct)

Cache errors Errors

0x48000001   ERROR_ALREADY_OPENED: The requested operation cannot be performed while the cache is open.
0x48000002   ERROR_NOT_OPENED: The cache must be open before attempting to perform the requested operation.
0x48000003   ERROR_REQ_PARAM_MISSING: The requested operation cannot be performed because a required property has not been set.
0x48000004   ERROR_WRONG_ARGUMENT: An invalid value has been passed for the method parameter specified in the error message.
0x48000005   ERROR_BACKEND_FAILURE: The cache cannot read data from or write data to external storage because an event handler has reported an error. Once the error state has been reset using reset_error_state, try again.
0x48000006   ERROR_BACKEND_FILE_FAILURE: The cache cannot read data from or write data to external storage because an event handler has reported a file error. Once the error state has been reset using reset_error_state, try again.
0x48000007   ERROR_INVALID_OPERATION: The requested operation is not valid in current context. Refer to the error message for additional information.
0x48000008   ERROR_STORAGE_FAILURE: An operation involving the cache storage file has failed.
0x48000009   ERROR_WRONG_ENCRYPTION_KEY: The specified cache encryption key is incorrect.
0x4800000A   ERROR_DIR_NOT_EMPTY: The cache has failed to delete all blocks from the cache storage file.
0x4800000B   ERROR_FILE_NOT_OPEN: The requested operation cannot be completed because the specified file is not open. Open it using file_open, and then try again.
0x4800000C   ERROR_PATH_NOT_FOUND: The requested operation cannot be completed because the specified path is not found.
0x4800000D   ERROR_FILE_NOT_FOUND: The requested operation cannot be completed because the specified file is not found.
0x4800000E   ERROR_FILE_ALREADY_EXISTS: The requested operation cannot be completed because the specified file already exists.
0x4800000F   ERROR_INVALID_FILE_STATE: The requested operation cannot be completed because the specified file is in an invalid state. Close it using file_close, and then try again.
0x48000010   ERROR_READWRITE_FAILURE: An operation of reading or writing the data from/to the cache has failed.
0x48000011   ERROR_OFFLINE: The requested operation cannot be completed because the external storage is offline.
0x48000012   ERROR_UNSUPPORTED: The specified combination of external storage capabilities is not supported by the cache. Please double-check that the reading_capabilities, writing_capabilities, and resizing_capabilities properties are set correctly.
0x48000013   ERROR_INTERNAL_OPERATION_CANCELED: The requested operation cannot be completed because it was canceled.
0x48000014   ERROR_INTERNAL_VAULT_CORRUPTED: The cache vault is corrupted. check_and_repair should be used to attempt to fix the vault.
0x48000015   ERROR_INTERNAL_VAULT_RECREATED: The cache vault has been corrupted beyond repair and has been recreated. This is not strictly an error but a nonplanned outcome.
0x49000001   ERROR_INTERNAL_ERROR_FIRST: An internal error has occurred. Please report the error details to the Callback Technologies support team.
0x4900000B   ERROR_INTERNAL_ERROR_LAST: An internal error has occurred. Please report the error details to the Callback Technologies support team.