ResourceManager.GetObject Caching

Last post 07-17-2007 12:54 AM by rstrahl. 1 replies.

Sort Posts:

  • ResourceManager.GetObject Caching

    07-16-2007, 8:55 PM
    • Loading...
    • michhes
    • Joined on 03-08-2007, 12:27 AM
    • Posts 3

    The ResourceManager.GetObject () documentation states the following:

     If you call the GetObject method multiple times with the same name parameter, do not depend on the return value being a reference to the same object. This is because the GetObject method can return a reference to an existing resource object in a cache, or can reload the resource and return a reference to a new resource object.

    Does this mean the ResourceManager caches objects or not? Arriving at my rm.GetObject invocation in the debugger and running the following snippet a few times results in different hash codes each time, leading me to believe the .NET 2.0 ResourceManager implementation is not doing any caching:

    object o1 = rm.GetObject (name, culture);
    o1.GetHashCode () 
    ...

    On the other hand, I assume satellite assemblies are loaded into the app domain when they're first requested and resources are sitting there in memory--negating the need for caching (apart from any custom code and the resource location\fallback logic).

    Any thoughts?

    Secondly, where's the best place to store a reference to a ResourceManager object in an ASP.NET app? Should it live in the HttpApplicationState or global.asax or somewhere else? 

  • Re: ResourceManager.GetObject Caching

    07-17-2007, 12:54 AM
    Answer
    • Loading...
    • rstrahl
    • Joined on 08-20-2003, 9:08 AM
    • Paia, Hawaii
    • Posts 249
    • ASPInsiders
      TrustedFriends-MVPs

    Are you sure you're looking at EXACTLY the same object? Different locale will give you a different hashtable.

    I've built a number of custom resource managers and in checking the provider loading from database I've only ever seen the ResourceReader  pulling data once for each resource set. So yeah that stuff definitely gets cached, although it's possible that under certain conditions (memory pressure? AppDomain unload) that the resources reload, but I've never seen this.

    In ASP.NET applications you shouldn't use a ResourceManager unless your loading assembly specific resources. If you're using ASP.NET's native functionality using the ResourceProvider and HttpContext.GetGlobalResourceObject/GetLocalResource object is the better way to go.

    If you do need to tack on a resource manager make it a static somewhere with a static constructor. More effcient than using HttpApplicationState.

    +++ Rick ---

    Rick Strahl [MVP]
    West Wind Technologies
    Making waves on the Web
    www.west-wind.com/weblog
Page 1 of 1 (2 items)
Microsoft Communities
Page view counter