I use a lot of functions that extract a specific data item from a file with many data items. I want these functions to load data (slow) and return the item (fast) on first call, but just return the item on subsequent calls. If I were using VB, I would declare static variables init along with other variables to hold the data, load the data and set init True on first call, and bypass the data load with an If init <> true then xxxx endif portion of the function on subsequent calls.
But variables listed within the {} of a Module don't persist from call to call. My workaround is to give the data an absurdly long variable name and exclude it from the the Module[{var1,var2,...} list, and use ValueQ to check if longvariablename has been evaluated. For example:
getPce[date_,column_] := Module[{dates, value, b, e},
If[! ValueQ[longvariablename], longvariablename = Import["path\\file];
value = SomeFunction[date_,column_]; (* get item(s) from longvariablename *)
]
This is a clumsy. I'm sure there is a nice Mathematica way to do this, but I've never been able to figure it out.