OPC XML-DA servers normally retrieve data from underlying systems, such as fieldbuses. Different client will then access these items through the OPC server. There may be situations, where many clients access the same OPC item over and over. These client requests will therefore lead to a significant load on underlying systems and may even exceed their capabilities.
One solution to this problem is caching: when the OPC server retrieves an item from an underlying system, it stores it for a predefined amount of time. These cached items are then available for OPC clients, therefore client requests do not necessarily lead to data retrieval from underlying systems.
In the client request message, the option ``MaxAge'' may be specified, denoting how old the item may be. If MaxAge is greater than the time the item is cached, the server will build the response message upon the cached item, otherwise the server will retrieve new data.
The PyOPC framework does automatically implement OPC item caching, if the server attribute ``AutoItemCache'' is set to true (which it is by default). The developer can also specify the attribute ``DefaultMaxAge'', which defines the maximum age in milliseconds for requests that do not provide the MaxAge option.
The exact item caching mechanism is illustrated in figure 8:
If an OPC Read request message is received by the server and ``AutoItemCache'' is set to true, the XDAServer method ``CachedRead'' is called. This method decides whether to return cached data regarding the MaxAge parameter or whether it calls the server's read method, which retrieves the data from the underlying system.
This way, the developer does not need to regard item caching, he has to code only the data retrieval itself. His read method will be only called if the maximum allowed age is smaller than the time, the item is cached.
Write operations update data in underlying devices. Therefore by default the read cache of a written item is flushed. However, in certain situations it may be appropriate not to clear the cache. Therefore PyOPC provides the option ``WritePurgeCache'' which can be set to false to omit the automatic cache flushing.