web services - Azure Appfabric Caching + WCF Webservices -
i have series of wcf web services hosted in windows azure , trying implement appfabric caching.
i struggling stateless nature of web services , need avoid expensive initialisation of datacachefactory , datacache objects.
i have wrapped datacachefactory in singleton seemed place start.....
imports microsoft.applicationserver.caching public class cache private shared _datacachefactory datacachefactory private shared _datacache microsoft.applicationserver.caching.datacache private sub new() end sub shared readonly property datacachefactory datacachefactory if isnothing(_datacachefactory) dim localtimeout new timespan(0, 10, 0) dim localcacheconfig new datacachelocalcacheproperties(10000, localtimeout, datacachelocalcacheinvalidationpolicy.timeoutbased) dim factoryconfig new datacachefactoryconfiguration() factoryconfig.localcacheproperties = localcacheconfig _datacachefactory = new datacachefactory(factoryconfig) end if return _datacachefactory end end property shared readonly property datacache microsoft.applicationserver.caching.datacache if isnothing(_datacache) _datacache = datacachefactory.getdefaultcache end if return _datacache end end property end class but when try use it, seems going out of scope , being recreated repeatedly instead of once per azure instance. if understanding things correctly comes down to.....where can store global variable in wcf web service doesn't go out of scope.
from can see code should doing want doing. thing suggest (which has nothing problem) put locking around creation e.g. shortest property:
private static _datacachelock new object() shared readonly property datacache microsoft.applicationserver.caching.datacache if isnothing(_datacache) synchlock _datacachelock) if isnothing(_datacache) _datacache = datacachefactory.getdefaultcache end if end synchlock end if return _datacache end end property it important have static datacachefactory not avoid costly initialisation, because each 1 of these objects create uses 1 of few cache connections have (you 5 lowest cache size).
static variables stay in scope unless web role or application pool gets restarted.
how catching datacachefactory being recreated?
Comments
Post a Comment