7 Replies Latest reply on May 2, 2011 9:09 PM by Ahmad Fattahi

    AF SDK Caching

    arm77

      Hi,

       

      I know AF SDK does cache AF Objects (AF Elements, Attributes).So subsequent calls to same element or attribute are much faster.

       

      Does any one know how many objects does AF SDK Cache and for how along.

       

      Basically i am trying speed up my calls.

       

       

       

      Thanks in advance

       

      AR

       

       

       

       

        • Re: AF SDK Caching
          mhalhead

          Abdul,

           

          Doing a quick check on my setup the default  for MaxObject was 10000 and CacheTime was 120 (seconds).That said you can manipulate the AFCache by setting the CacheTime and MaxObjects properties. There is also a Clear method. 

           

          You can find the details in the AFSDK help, look for "AFCache Class".

           

          I would like to point out that you cannot control which AF objects get cached; it is an all or nothing. This is not necessarily a bad thing as it has kept the cache simple. To turn the cache off set the MaxObjects = 0.

            • Re: AF SDK Caching
              arm77

              Micheal,

               

              Thanks fro the Reply.

               

              Will the cache store the value of the object, or just the references,

               

              for example,if i do a GetValue, will it get from the cache or will it make a trip to the server

               

              Thanks in advance

               

              AR

                • Re: AF SDK Caching

                  Caching of values would be dependant on how the Data Reference caches, if at all, values.  The logic within GetValue/GetValues would need to implement that caching; I cannot see that the AF Cache would do so because it would easily be out of sync with the source data store.  Need an OSIsoft AF developer to clarify...

                    • Re: AF SDK Caching
                      cmanhard

                      The PI Point Data Reference does not currently cache - thus, any call to GetValue results in a call to the server.  This is why it is important to use AFAttributeList when retrieving values, so that calls can be optimized to reduce round trips to PI.  The Table Lookup Data Reference cache's the AFTable based on the cache settings within the AF Table.  Attributes with no data reference use the cached value.  If having these updated is important, then calls to Database.Refresh ensure that any cached items that have been modified since caching will be re-retrieved.

                        • Re: AF SDK Caching
                          jmolines

                          Hi,

                           

                          When I try to get a value from an attribute with no Data Reference, I always get the old value even if I use

                           

                          OSIsoft.AF.Diagnostics.AFCache.CacheTime = 0;

                           

                          I only get the new value after I call Database.Refresh().

                           

                          Is OSIsoft.AF.Diagnostics.AFCache.CacheTime used for attributes with no Data Reference ? or do I have to call Refresh method even if CacheTime is set to 0 ?

                           

                          Thanks in advance

                            • Re: AF SDK Caching
                              Ahmad Fattahi

                              The AFCache refers to the cache that keeps an object in memory so that it does not get garbage collected so that the application does not have to keep a reference to it. This increases performance because a recently used object will typically be used again. When an object is garbage collected, the AFSDK must retrieve the objects information from the server.

                               

                              The attribute value with no DataReference will be kept in memory with the object. Therefore its value will not update until it is retrieved from the server again either through a garbage collection or the client calling Refresh on the object.

                                • Re: AF SDK Caching
                                  Ahmad Fattahi

                                  Here is some more information. Setting the AFCache.CacheTime to 0 disables the AFSDK from keeping a reference to the object, but the .NET Framework will decide when the object will be garbage collected.  As long as there is a reference to the object in memory, then the object will not be garbage collected. It will also not be garbage collected until the .NET Framework decides that it needs to reclaim memory.