dpSetCache()
The function sets the content of the cache.
Synopsis
int dpSetCache(string dp1, <type1> var1 [, string dp2, <type2>
var2, ...]);
Parameters
Parameter | Description |
---|---|
dp1 | The datapoint that is set. |
var1 | The value that is set. NOTE: If the dp1 is a list of elements, the variable type1 has to be dyn_anytype. |
Return Value
The function returns 0 but in case of errors -1.
Errors
You can retrieve errors by using the function getLastError(). Errors can be, for example, missing arguments or a missing datapoint.
Description
Sets the content of the cache. More precisely the function writes the original values of the datapoints into the cache. The cache functions allow faster writing as well as query of datapoints.
EXAMPLE
The example initalizes the cache with datapoint values and writes the values into the cache and to the database. The values are displayed and you can see that the values from the cache are read much faster than from the database. You can find the function calls for the functions "foo" and "delCach" below. Add the function calls, for example, to a button.
main()
{
/* Function calls of functions shown further below */
foo();
delCach();
}
Add the following code to the "initialize" script of your panel.
main()
{
// Initialize the Cache with all the Example DPs
string sDpeFiler = "ExampleDP_*.";
// all DPEs that start with 'ExampleDP_'
dpQueryConnectSingle("dpGetCacheConnectCB", FALSE, "myIdent",
"SELECT '_original.._value' FROM '" + sDpeFiler + "' WHERE
_LEAF");
dyn_errClass dErr = getLastError();
if ( dynlen(dErr) )
{
throwError(dErr);
// debug error in the LogWiever
return;
}
}
Add the following code to the scope lib of your panel:
#uses "dpGetCache.ctl"
// Check if the value in the cache is equal to the DB value
bool isCacheOk(string sDpe = "ExampleDP_Arg1.")
{
// Get the cache value from the DP "ExampleDP_Arg1."
float fValCahced;
dpGetCache(sDpe, fValCahced);
// get the value directly from DB
float fVal;
dpGet(sDpe, fVal);
return (fVal == fValCahced);
}
void foo()
{
float fOrig;
dpGetCache("System1:ExampleDP_Arg1.", fOrig);
float fVal = fOrig;
int iCount;
while (fVal < ( fOrig + 10 ) && iCount < 20)
{
iCount ++;
DebugN("iCount :: inc", iCount, "fVal", fVal);
inc("System1:ExampleDP_Arg1.");
dpGetCache("System1:ExampleDP_Arg1.", fVal);
}
DebugN("g_dpGetCache", g_dpGetCache);
int iCount;
while (fVal > fOrig && iCount < 20)
{
iCount ++;
DebugN("iCount :: dec", iCount, "fVal", fVal);
dec("System1:ExampleDP_Arg1.");
dpGetCache("System1:ExampleDP_Arg1.", fVal);
}
}
void inc(string sDpe)
{
// set your value into the cache
float fVal;
dpGetCache(sDpe, fVal);
fVal++;
dpSetCache(sDpe, fVal);
}
void dec(string sDpe)
{
// set your value into the DB
float fVal;
dpGetCache(sDpe, fVal);
fVal++;
dpSet(sDpe, fVal);
/* The value is written to the database but you can see that the
writing to the database is much slower than the writing to the
cache */
}
//Löscht den DP ExampleDP_Arg1 aus dem Cache
//Deletes the ExampleDP_Arg1 from the cache
void delCach()
{
float RetVal;
dpRemoveCache("System1:ExampleDP_Arg1.:_original.._value");
dpGetCache("ExampleDP_Arg1.",RetVal );
DebugN("Cache value after Remove Cache:", RetVal);
}
Assignment
Cache functions
Availability
UI, CTRL