Quantcast
Channel: Xojo Programming Forum - Latest topics
Viewing all articles
Browse latest Browse all 3762

Caching computed properties

$
0
0

I have a class that has multiple computed properties.
The Getter looks up the value in a dictionary and then returns it.
The set stuff the dictionary.

I have a ‘bunch’ of these methods and I’d like to cache the value from the getter such that it doesn’t need to look it up but knows the value from the last call.

I believe I need to add two static properties for each of the getter/setters.
i.e.

Public Property mValue as integer
   static cached as boolean = false
   static cachevalue as integer

   if cached then
      return cachevalue
   else
      cachevalue = d.lookup(x)
      cached = true
   end if
   return cachevalue
End Get

I am wondering if that static cached variable is scoped correctly. Wil each instance of this class have it’s own state?

5 posts - 5 participants

Read full topic


Viewing all articles
Browse latest Browse all 3762

Trending Articles