Hi ,
i have set cache per minutes 180 in my web block , but how can i clear cache when i want ,
Case 1: when new user login
Case 2 : logout user or any user close brwoser
Case 3: Clear with any action
please provide solution regarding that.
Below the source code.
Case 1: You can't, I have not implemnted that yet. It will delete itself after the period it is set to be saved.
Case 2: Usermanagement is managed by outsystems. You should not be using application cache for usermanagement or authentification.
Case 3: Add a new value with the same key value and set the time to 0. It should delete itself after saving.
This extention is used serverside to store data thet is not businesslogic and prevents you from doing unnescesary requests to your database.
Please view the source for more info;
public void MssSaveToCache(string ssKeyName, string ssValue, int ssExpirationTimeHours, int ssExpirationTimeMinutes, int ssExpirationTimeSeconds) { // TODO: Write implementation for action
MemoryCache cache = MemoryCache.Default; //new MemoryCache("MyNewCachename"); var policy = new CacheItemPolicy(); policy.SlidingExpiration = new TimeSpan(ssExpirationTimeHours, ssExpirationTimeMinutes, ssExpirationTimeSeconds);
if (cache[ssKeyName] == null) { cache.Add(new CacheItem(ssKeyName, ssValue), policy); } else { cache.Set(new CacheItem(ssKeyName, ssValue), policy); } }
public void MssGetFromCache(string ssKeyName, out string ssValue) { ssValue = ""; MemoryCache cache = MemoryCache.Default; //new MemoryCache("MyNewCachename"); ssValue = (string)cache[ssKeyName]; if (ssValue == null) { ssValue = ""; var policy = new CacheItemPolicy(); policy.SlidingExpiration = new TimeSpan(2, 0, 0); cache.Add(new CacheItem(ssKeyName, ssValue), policy); } } public void MssClearCache() { // TODO: Write implementation for action } // MssClearCache