Reputation: 1
My question here is why my feed_expiration_date datetime variable becomes null on each request only in server environment it works perfectly on local environment I have a web garden (8 process workers) on both local and server environment.
actually since I have 8 process worker so I have different process ID for example PID:1234 and initially it has the feed_expiration_date value set to some date and when user again request the page with in the expiration period time if the process gets same PID: 1234 then PID:1234 should hold its previous value. in my local it is working as expected but on the server environment it is not working any help would be highly appreciated
public static class CacheManager
{
public static ClientData ClientDataCache
{
get
{
return GetClientDataCacheByID(HostInstanceID);
}
}
public static ClientData GetClientDataCacheByID(int instance_id)
{
try
{
ClientData data = null;
if (instance_id != 0)
data = client_cache_data_dictionary.ContainsKey(instance_id) ? client_cache_data_dictionary[instance_id] : null;
if (data == null || data.GlobalSettingsCache == null || DateTime.UtcNow > data.date_cached.AddHours(1))
return GenerateClientData();
return data;
}
catch (Exception ex)
{
return null;
}
}
private static ClientData GenerateClientData()
{
lock (InstanceLocker)
{
ClientData data = null;
int instance_id = HostInstanceID;
if (instance_id != 0)
data = client_cache_data_dictionary.ContainsKey(instance_id) ? client_cache_data_dictionary[instance_id] : null;
if (data == null || data.GlobalSettingsCache == null || DateTime.UtcNow > data.date_cached.AddHours(1))
{
data = new ClientData(true);
if (data != null && data.InstanceID > 0)
{
int id = data.InstanceID;
HostInstanceID = id;
client_cache_data_dictionary[id] = data; // To prevent race conditions, this has to happen prior to client_data_cache_lock_dictionary[id] = new object();
client_data_cache_lock_dictionary[id] = new object(); // This has to happen 2nd, not first
if (Portals.Utils.IsEC2)
{
try
{
if (!global_cache_mgr_init)
{
GlobalCacheManager.GlobalCacheManager.Initialize(GlobalCacheManager.Enumerations.SystemLocations.AdminPortal, !Portals.Utils.IsEC2 ? "us-west-2" : null);
global_cache_mgr_init = true;
GlobalCacheManager.GlobalCacheManager.Start();
}
}
catch (Exception ex)
{
Emails.SendAdminEmail("Error Init/Start GCM on ClientCache.cs", ex.StackTrace);
}
}
}
Portals.Utils.LogErrorFeed("ReadGSFromDB","true PID: " + System.Diagnostics.Process.GetCurrentProcess().Id);
}
else
{
Portals.Utils.LogErrorFeed("ReadGSFromCache", "true PID: " + System.Diagnostics.Process.GetCurrentProcess().Id);
}
return data;
}
}
public class ClientData
{
public ClientData(bool initdata = false) {
if (initdata) IntializeClientData();
}
private List<SurveysAndFeaturesFeedResult> surveyAndFeaturesFeeds = null;
public DateTime date_cached { get; set; }
public DateTime? feed_expiration_date { get;set;}
private object surveys_features_generate_locker = new object();
public void GenerateSurveysAndFeaturesCache(bool force_refresh = false)
{
if(this.InstanceID != 0)
{
lock(surveys_features_generate_locker)
{
if (this.surveyAndFeaturesFeeds == null || force_refresh)
{
this.surveyAndFeaturesFeeds = CakeFeed.GetSurveysAndFeaturesFeedResult();
this.feed_expiration_date = DateTime.UtcNow.AddHours(this.global_settings.CakeFeedCacheDurationHoursCKM);
}
}
if(force_refresh && this.surveyAndFeaturesFeeds != null)
{
Portals.Utils.RefreshPortals();
}
}
}
public List<SurveysAndFeaturesFeedResult> SurveysAndFeaturesFeed
{
get
{
if(this.global_settings.EnablePresentIcon && (surveyAndFeaturesFeeds == null || feed_expiration_date == null || feed_expiration_date < DateTime.UtcNow))
{
GenerateSurveysAndFeaturesCache();
}
return (surveyAndFeaturesFeeds == null) ? new List<SurveysAndFeaturesFeedResult>() : surveyAndFeaturesFeeds.ToList();
}
}
}
}
And from handler.ashx I call this as CacheManager.ClientDataCache.SurveysAndFeaturesFeed.OrderByDescending(x=>x.PublishDate).ToList();
Upvotes: 0
Views: 76