Replies: 1 comment
-
Hi @andy-rsa - TL;DR For most uses you can assume a static variable is a good cache for the kind of data you have in mind. The situation differs a bit according to whether you are targeting .NET Framework 4.x or .NET core (.NET 6+). For .NET Framework, each add-in is isolated in its own AppDomain. A new AppDomain is created if you reload the add-in (e.g. with File -> Open or by unchecking and recheckling in the Add-Ins dialog). Otherwise, the AppDomain is stable and any types loaded and static data there will be retained for the duration of the Excel process. For .NET core runtimes (.NET 6+) the runtime only supports a single AppDomain in the process. So, all add-ins that targeting .NET core are loaded into the same AppDomain. There is a partial isolation of the add-ins through the One issue you'll run into with the caching and 'object handle' approach is how to clean the cache. For the upcoming version 1.9 we are baking the object handle support into Excel-DNA itself.
Alternatively, you can mark the class with |
Beta Was this translation helpful? Give feedback.
-
I have some large data that my .NET code needs but I don't want to manage in Excel. Can I cache the data in .NET safely?
Q: as long as excel is up and running, is the process/appdomain is stable and constant?
My concern would be that the .net process/appdomain would be killed off and re-created between calls.
belief: if the process/appdomain is stable, I can create a dictionary and use that to cache results.
Background: I have UDF that return a lot of data, but I don't need to see it all in Excel. I do however, need all that data to make a subsequent call to other UDFs. I'd like to create a key for the data, store it in a cache at the process/appdomain level and only return the key to excel. I'd have a set of UDFs that all accept cache keys for the large sets of data (by convention).
Thank you
p.s. I did a summary search for similar topics but didn't find anything. MS Copilot gave an answer that indicated that Excel-DNA operates inside the Excel process space and that the appdomain for .NET would remain constant while the extension was installed, but i'd like to confirm before I get too deep.
Beta Was this translation helpful? Give feedback.
All reactions