c# - MVC session variables storage Memory vs disk caching -
i store number of large bitmaps make dynamically, using session variables using following:
public static mysession current { { mysession session = (mysession)httpcontext.current.session["__mysession__"]; if (session == null) { session = new mysession(); httpcontext.current.session["__mysession__"] = session; } return session; } }
would using disk caching better, , if there example or documentation. in advance.
storing large items in sessionstate
a bad idea - limit scalability of application due usage of server memory. if move sessionstate sql, add io , storage requirements of app.
below, i'm assuming have dynamic image generation action on controller referenced, e.g. <img src='http://myserver/image/generate/wmavatar' >
, i.e. reason rendering dynamic images consumption of browser?
if dynamic images specific 'per user', or per session: instead of using session state, generate , deliver images dynamically appropriate http caching headers, , should cached browser. may still need handle case if-modified-since
requests
if images can shared between multiple users, or @ least re-used same user across sessions yes, store them disk (e.g. ssd) in folder configured appropriate caching (and precompute images if can) , img
links no longer dynamic (http://myserver/images/123456.jpg
). need handle cleanup of expired images, , handle 404 type errors deleted images. above, use http caching headers reduce unnecessary i/o. nowadays, caching in memory key value / nosql database common, e.g. redis, can scale in cloud, e.g. elasticache
Comments
Post a Comment