gtpc2m9bC/C++ Language Support User's Guide

updateCacheEntry-Add a New or Update an Existing Cache Entry

This function adds a new cache entry or updates an existing cache entry.

Format

#include  <c$cach.h>
long       updateCacheEntry(const cacheToken *cache_to_update,
                            const void *primary_key,
                            const long *primary_key_length,
                            const void *secondary_key,
                            const long *secondary_key_length,
                            const long *size_of_entry,
                            const void *entry_data,
                            const long *timeout,
                            const char *invalidateOthers);   

cache_to_update
The returned cache_token from the newCache function that created the logical record cache.

primary_key
A pointer to a field that contains the value for the primary key.

primary_key_length
The length of the primary key for a cache entry. The length specified must be equal to or less than the maximum value specified for the newCache function.

secondary_key
A pointer to a field that contains the value of the secondary key. If a secondary key was not specified for the newCache function, this field is ignored and will contain a NULL pointer.

secondary_key_length
The length of the specified secondary key. The length specified must be equal to or less than the maximum value specified for the newCache function.

size_of_entry
A pointer to a field that contains the length of the passed entry data.

entry_data
A pointer to the area that contains the actual entry data to be saved in the logical record cache.

timeout
An integer indicating the number of seconds that a cache entry can reside in cache before it is flushed. Once this value is reached, the cache entry is marked as not valid and results in a not found condition. This forces a cache update for the cache entry. If a nonzero value is specified, this value overrides the value specified for castout_time for the newCache function.

invalidateOthers
A pointer to a char that has been set to either Cache_NoInvalidate or Cache_Invalidate. If one of the following conditions is met, the updateCacheEntry function only modifies this processor's cache:

If the pointer to a char is set to Cache_Invalidate, logical record cache support tries to invalidate any other processor's cache entry for the specified entry.

Normal Return

CACHE_SUCCESS
The function is completed successfully.

Error Return

One of the following:

CACHE_ERROR_HANDLE
The cache_token provided for the cache_to_update parameter is not valid.

CACHE_ERROR_PARAM
The value passed for one of the parameters is not valid.

Programming Considerations

To ensure data integrity, the caller must ensure that a locking mechanism is used when using the updateCacheEntry function.

Examples

The following example adds a cache entry to the file system directory cache.

#include <c$cach.h>
#include <i$glue.h>
 
    struct ilink * link;
    struct TPF_directory_entry new_tde =
        { TPF_FS_DIRECTORY_CURRENT_VERSION };
    const long dataLength = sizeof(new_tde);  /* size of directory entry */
    const long primaryKeyLgh = strlen( link->ilink_file_name );
    const long secondaryKeyLgh = sizeof(ino_t);   /* INODE number    */
    struct icontrol * contrl_ptr;             /* pointer file system control area */
 
/*  setup file system directory entry with values from the input  */
 
    new_tde.TPF_directory_entry_ino =
        link->ilink_file_inode_ordinal;
    new_tde.TPF_directory_entry_igen =
        link->ilink_file_inode->inode_igen;
 
/*  get pointer to file system directory cache token if one  */
 
     contrl_ptr = cinfc_fast_ss(CINFC_CMMZERO,
                   ecbptr()->ce1dbi );
 
     if (contrl_ptr->icontrol_dcacheToken.token1 != 0)
 
/*   have a directory cache, update it with directory entry       */
 
         updateCacheEntry(&contrl_ptr->icontrol_dcacheToken,
                          link->ilink_file_name,
                         &primaryKeyLgh,
                         &link->ilink_parent_inode->inode_ino,
                         &secondaryKeyLgh,
                         &dataLength,
                         &new_tde,
                          NULL,
                          NULL );
 

.

Related Information