Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my MVC app caching this setting?

I have an Email-listening application that handles incoming mails, depending on the "Bucket" (or Queue) the emails are in. One of the settings for each bucket is "AutoRespond". If AutoRespond is true, I send a confirmation email back to the sender.

However, when I change the AutoRespond setting, it doesn't seem to be taking effect. I'm familiar w/ setting OutputCache on a controller, but this logic below is from my Email-listening service cs file.

if (myObject.Bucket.AutoRespond)
{
    SendEmailConfirmation(someArgs);
}

This if statement is still evaluating as True, even though I can see it set to False in the database. If I restart my Email-listening service, all is well, and this if statement evaluates correctly. Any ideas?

like image 261
WEFX Avatar asked Jan 01 '26 03:01

WEFX


2 Answers

Probably the problem is that settings are read from the database just when the application starts...then probably they are stored in a static variable or in the application state dictionary. If this is the case, you may solve it by writing an admin page that after having changed the settings, forces to reload the settings from the database.

like image 77
Francesco Abbruzzese Avatar answered Jan 05 '26 05:01

Francesco Abbruzzese


You can also try a web.config app setting, changing the value automatically restarts the app (not sure if that's practical or not for you but another option nonetheless)

web.config:

<appSettings>
    <add key="AutoRespond" value="true" />
</appSettings>

c# logic here:

bool autoRespond = false;
bool.TryParse(System.Configuration.ConfigurationManager.AppSettings["AutoRespond"], out autoRespond);
like image 38
Justin Soliz Avatar answered Jan 05 '26 06:01

Justin Soliz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!