Static variables are not static for very long

I have been fighting the “10 describe calls” per request governor limit in some code that clones an object graph that includes more than 10 custom types. In one (dead-end) approach I was trying to cache some of the describe information in a static variable referencing a collection. This revealed the surprising (to a Java developer at least) fact that static variables only have request scope and so are no use for trying to build session or application scope caches:

Static variables are only static within the scope of the request. They are not static across the server, or across the entire organization.

From Static and Instance.

Advertisements

One thought on “Static variables are not static for very long

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s