简体   繁体   中英

Structuremap 3 - Caching a single object instance for all request on application start

Does anyone know how to cache object on Web application start with structuremap 3? Is singleton method right approach ( o.For().Singleton().Use()), if yes is it cached?

Thanks

It depends on your needs. If your object never changes, singleton might be a good choice, but remember that the same object created at the start of your application will be used until the app is restarted. In most situations you want your cache objects to be refreshed once in a while to provide the current data. In such scenario you should use a custom structuremap lifecycle. Please take a look at http://notherdev.blogspot.com/2014/06/structuremap-time-expiring-objects-cache.html for a good example of possible implementation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM