/// <summary> /// Gets the current frontpage settings, attempting to use a cached /// version without needing any locks, and loading an instance if needed /// </summary> /// <returns>The frontpage settings</returns> public async Task <FrontpageSettings> GetFrontpageSettingsAsync() { var tmp = m_frontpageSettings; if (tmp != null) { return(tmp); } using (await m_lock.LockAsync()) { if (m_frontpageSettings != null) { return(m_frontpageSettings); } return(m_frontpageSettings = await DB.RunInTransactionAsync(db => db.SelectItemById <FrontpageSettings>(LinkDatabase.FRONTPAGESETTINGS_KEY) )); } }
public async Task <IResult> Put(FrontpageSettings settings) { if (settings == null) { return(BadRequest); } settings.ID = LinkDatabase.FRONTPAGESETTINGS_KEY; if (settings.Mode == FrontpageMode.Redirect) { if (string.IsNullOrWhiteSpace(settings.RedirectUrl)) { return(Status(BadRequest, "Redirect requires a target url")); } if (settings.InternalRedirect && !settings.RedirectUrl.StartsWith("/")) { return(Status(BadRequest, "Internal redirect urls must start with a forward slash")); } if (settings.InternalRedirect && !System.Uri.IsWellFormedUriString(settings.RedirectUrl, System.UriKind.Relative)) { return(Status(BadRequest, "Malformed internal redirect url")); } if (!settings.InternalRedirect && !System.Uri.IsWellFormedUriString(settings.RedirectUrl, System.UriKind.Absolute)) { return(Status(BadRequest, "Malformed absolute redirect url")); } } var res = Json(await DB.RunInTransactionAsync(db => db.UpdateItem <FrontpageSettings>(settings) )); await Cache.InvalidateFrontpageSettingsAsync(); return(res); }
/// <summary> /// Clears the currently cached instance of the frontpage settings /// </summary> /// <returns>An awaitable task</returns> public async Task InvalidateFrontpageSettingsAsync() { using (await m_lock.LockAsync()) m_frontpageSettings = null; }