3 Replies Latest reply on Dec 10, 2015 11:17 PM by stephen.oconnor

    AF SDK Cache does not update


      Hey all,

      I'm working on a ASP.Net HTTP Handler that returns Pi and AF data using the AF SDK 4.0. I've noticed that attributes from AF do not seem to properly update, sometimes for several hours.


      AFSDK.config in \ProgramData\OSISoft\AF\ reads that it should have a time of 120s.


      My current solution is to have the IIS AppPool recycle every 5 minutes, which is not ideal as it leads to longer page loads and the occasional HTTP-500 error, but does solve this problem.


      Has anyone encountered this before?


      AF SDK Version:

      AF Server


      Thank you,


        • Re: AF SDK Cache does not update
          Marcos Vainer Loeff

          Hello Stephen,


          Which type of application are you developing? ASP.NET MVC?


          PI AF SDK provides the AFCache class exposing the CacheTime and MaxObjects properties which could be used to set up the cache as you want to. If you call the Clear method, it will remove all items from the AF SDK cache, forcing the new request to get updated data from the server.


          If you want to force the objects to be updated, you can call AFDatabase.Refresh() method. Nevertheless, a less expensive approach is to get all changed items through the AFDatabase.FindChangedItems and refresh the objects that were changed. There is a complete example on the PI AF SDK programming reference available after installing PI AF Developer Tools.


          Hopefully, with these techniques you will be able to control the AF SDK cache much better!

          2 of 2 people found this helpful
            • Re: AF SDK Cache does not update

              Thank you for the reply. I'm working on a ASP.Net 4.0 WebForms application.


              I have checked out AFCache before and it looks like all of its parameters are correct. CacheTime returns 120 which matches what I'm seeing in AFSDK.config.


              I'm trying to find a solution that supports a production environment, so clearing the cache each request is not ideal.


              FindChangedItems is very interesting, however the documentation reads "Note: This API is now obsolete". Is this the right way forward?


              EDIT: My question about "This API is now obsolete is a misunderstanding. It specifically refers to the FindChangedItems(Boolean, AFTime, AFTime) signature, not the FindChangedItems(Boolean, Int32, Object, Object) signature.

              • Re: AF SDK Cache does not update

                I just put together the sample code to see if this could work...


                double val1, val2;
                var att = AFAttribute.FindAttribute("TEST|VALUE", DB);
                object af_cookie = null;
                object db_cookie = null;
                while (true)
                    val1 = (double)att.GetValue().Value;
                    List<AFChangeInfo> list = new List<AFChangeInfo>();
                    list.AddRange(AF.FindChangedItems(false, int.MaxValue, af_cookie, out af_cookie));
                    list.AddRange(DB.FindChangedItems(false, int.MaxValue, db_cookie, out db_cookie));
                    AFChangeInfo.Refresh(AF, list);
                    val2 = (double)att.GetValue().Value;
                    Console.WriteLine("{0}: {1:0} -> {2:0}", DateTime.Now, val1, val2);


                As you can see, every five seconds I read a value, update the database, read again, print, and wait.



                Pretty awesome! Thank you so much.


                To correct the site, I'll add some code very similar to what's above to Global.asax.cs. If anyone needs it, let me know and I'll be happy to post it.


                As an aside, this code was also not updated after AFCache's timeout period. Maybe I'm not understanding something but that doesn't seem right.