dpGetCache()

The function returns the content of the cache.

Synopsis

int dpGetCache(string dp1 | dyn_string dp1, <type1> &var1 [, string|dyn_string dp2, <type2> &var2,...]);

Parameters

Parameter Description
dp1 The datapoint attribute that is queried.
var1

The value of the queried datapoint is written to this variable.

NOTE: If the dp1 is a list of datapoints, the variable var1 must be a 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

Returns the content of the cache. More precisely the function returns the online values of the datapoints that are set by using dpSetCache(). 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 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