У меня довольно стандартное приложение MVC3. Я пытаюсь сохранить в кеше некоторые данные, относящиеся ко всему приложению (а не ко всем пользователям) (в данном случае, Theme
объект / имя). При отладке (на сервере разработки, который интегрируется с Visual Studio), если я вызываю SwitchTheme
, я сразу вижу новую тему. На IIS7, любая тема была кэширована, остается в кэше; не обновляется до новой темы.
Редактировать: Некоторые коды:
public static Theme CurrentTheme { get {
Theme currentTheme = HttpContext.Current.Cache[CURRENT_THEME] as Theme;
if (currentTheme == null)
{
string themeName = DEFAULT_THEME;
try
{
WebsiteSetting ws = WebsiteSetting.First(w => w.Key == WebsiteSetting.CURRENT_THEME);
if (ws != null && !string.IsNullOrEmpty(ws.Value))
{
themeName = ws.Value;
}
}
catch (Exception e)
{
// DB not inited, or we're installing, or something broke.
// Don't panic, just use the default.
}
// Sets HttpContext.Current.Cache[CURRENT_THEME] = new themeName)
Theme.SwitchTo(themeName);
currentTheme = HttpContext.Current.Cache[CURRENT_THEME] as Theme;
}
return currentTheme;
} }
public static void SwitchTo(string name)
{
HttpContext.Current.Cache.Insert(CURRENT_THEME, new Theme(name), null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(30));
// Persist change to the DB.
// But don't do this if we didn't install the application yet.
try
{
WebsiteSetting themeSetting = WebsiteSetting.First(w => w.Key == WebsiteSetting.CURRENT_THEME);
if (themeSetting != null)
{
themeSetting.Value = name;
themeSetting.Save();
}
// No "else"; if it's not there, we're installing, or Health Check will take care of it.
}
catch (Exception e)
{
// DB not inited or install not complete. No worries, mate.
}
}
Я не уверен, где проблема. Я вызываю тот же метод и обновляю кеш; но IIS7 просто показывает мне старую версию.
Я могу отключить кэширование вывода в IIS, но это не то, что я хочу сделать. В лучшем случае это выглядит как хакерский обходной путь.