Refresh configuration cache¶
This operation keeps the library's shared ConfigurationSettings payload aligned with the Environment API without paying the cost of a network round trip on every configuration read. It throttles refresh checks to a configurable interval, reloads the full payload only when the server reports newer data, and updates the interval that governs future refresh checks.
| Field | Value |
|---|---|
| Operation ID | OP-ENV-002 |
| Trigger | Configuration-backed operation touches Configurations or GetConfigSettingInfo |
| Inputs | Requested constructor sections, derived ApplicationId, derived ApplicationHost |
| Outputs | Populated or refreshed ConfigurationSettings cache and updated refresh interval |
| Primary components | EnvironmentServiceBase.Configurations, EnvironmentServiceBase.RefreshConfigurationIfNewer, EnvironmentServiceBase.LastRefreshed, EnvironmentServiceBase.DoNewerSettingsExist |
| Entry point | SAIF.Framework.Security.EnvironmentApi\Services.Common\EnvironmentServiceBase.cs |
Steps¶
- Read
LastRefreshedto learn the newest timestamp the Environment API reports for this application's settings (BR-002). - If no cache exists yet, seed
_lastRefreshCheckedand_lastRefreshedwithDateTime.Nowso the initial load can proceed without waiting on a prior check. - If the previous refresh check still falls within
AllowRefreshCheckInSeconds, reuse the cached_lastRefreshedvalue instead of calling the service again — this is what keeps refresh checks cheap under load. - Otherwise call
/v2/settings/{ApplicationId}/lastRefreshedand parse the returned timestamp. - Compare the service timestamp with
_configurations.LastLoadedthroughDoNewerSettingsExist, and stop here when the cache already reflects the newest known data. - Build the settings URL that matches how this service instance was configured.
- Use
/v2/settings/{ApplicationId}/{ApplicationHost}/valuewhen no sections were requested. - Use
/v2/settings/{ApplicationId}/{ApplicationHost}/{sections}/value?includeTrackSettings=truewhen the constructor supplied one or more sections. - Download and deserialize the JSON payload into a new
ConfigurationSettingsinstance (BR-002). - Stamp
LastRefreshedwith the server value captured earlier andLastLoadedwith the local current time, so subsequent staleness checks compare against this refresh. - Verify that the downloaded settings dictionary contains
checkforupdatedsettingsinseconds. If the key is missing, throwKeyNotFoundExceptionso refresh throttling can never silently fall back to an undefined interval (BR-003). - Convert
checkforupdatedsettingsinsecondstointand store it inAllowRefreshCheckInSecondsso it governs the next refresh check.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([Configuration lookup needs cache]) --> LastRefreshed[Read LastRefreshed]
LastRefreshed --> Reload{Cache missing or stale?}
Reload -->|No| EndNo([Reuse current cache])
Reload -->|Yes| Url[Build settings URL]
Url --> Download[Download and deserialize payload]
Download --> Check{Refresh interval key present?}
Check -->|No| Fail([Throw KeyNotFoundException])
Check -->|Yes| Save[Store cache and refresh interval]
Save --> EndYes([Return refreshed cache])
Failure and edge-case behavior¶
- A missing
EnvironmentApiUrlenvironment variable throws before any HTTP request is issued. - The initial
LastRefreshedread uses local time when no cache exists yet, so the very first configuration access always proceeds without an extra round trip to check for staleness. - The throttle interval is replaced by the freshly downloaded
checkforupdatedsettingsinsecondsvalue on every successful refresh, so operators can shorten or lengthen the interval by changing that setting alone. - Configuration missing the refresh-interval key stops the operation with
KeyNotFoundExceptionrather than defaulting to a hidden interval.
Related documentation¶
Sources¶
- SAIF.Framework.Security.EnvironmentApi\Services.Common\EnvironmentServiceBase.cs