Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add .Net caching to docs #3839

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions docs/docs/clients/server-side.md
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,7 @@ private static FlagsmithClient flagsmith = FlagsmithClient

// Enable in-memory caching for the Flagsmith API.
// Optional.
// See Caching section below for more details.
// Defaults to not cache anything.
.withCache(FlagsmithCacheConfig.builder().enableEnvLevelCaching("cache-key").build())

Expand Down Expand Up @@ -1156,36 +1157,41 @@ _flagsmithClient = new FlagsmithClient(
# Override the default Flagsmith API URL if you are self-hosting.
# Optional.
# Defaults to https://edge.api.flagsmith.com/api/v1/
apiUrl: "https://flagsmith.myproject.com"
apiUrl: "https://flagsmith.myproject.com",

# Controls which mode to run in; local or remote evaluation.
# See the `SDKs Overview Page` for more info
# Optional.
# Defaults to False.
enableClientSideEvaluation: false;
enableClientSideEvaluation: false,

# Controls whether Flag Analytics data is sent to the Flagsmith API
# See https://docs.flagsmith.com/advanced-use/flag-analytics
# Optional
# Defaults to false
enableAnalytics: false
enableAnalytics: false,

# When running in local evaluation mode, defines
# how often to request an updated Environment document in seconds
# Optional
# Defaults to 60 seconds
environmentRefreshIntervalSeconds: 60
environmentRefreshIntervalSeconds: 60,

# Enables caching support.
# See Caching section below for more details.
# Optional.
cacheConfig: new CacheConfig(true),

# You can pass custom headers to the Flagsmith API with this Dictionary.
# This can be helpful, for example, when sending request IDs to help trace requests.
# Optional
# Defaults to None
customHeaders: <Dictionary>
customHeaders: <Dictionary>,

# How often to retry failed HTTP requests
# Optional
# Defaults to 1
retries: 1
retries: 1,

# The network timeout in seconds.
# Optional.
Expand Down Expand Up @@ -1342,7 +1348,7 @@ const flagsmith = new Flagsmith({
/*
Adds caching support
Optional
See https://docs.flagsmith.com/clients/server-side#caching
See Caching section below for more details.
*/
cache: {
has: (key: string) => bool,
Expand Down Expand Up @@ -1754,6 +1760,29 @@ cache.invalidate(projectLevelCacheKey);
final FlagsAndTraits flags = cache.getIfPresent(projectLevelCacheKey);
```

</TabItem>
<TabItem value="dotnet" label=".NET">

To enable caching, you can initialise the SDK like this:

```csharp
var flagsmithClient = new FlagsmithClient(Fixtures.ApiKey,
httpClient: mockHttpClient.Object,
enableClientSideEvaluation: true,
cacheConfig: new CacheConfig(true));
```

If the cacheConfig argument is passed during initialization with its `Enabled` property set to `true`, the SDK will make
use of cached values initially, and then make required API calls as usual and update the cache under the hood. Note that
this is only the case for remote evaluation mode and does not affect the behaviour of local evaluation mode.

The Cache will be used when retrieving environment or identity flags. When caching the environment flags, the SDK will
use the unique environment key as the cache key. When caching the identity flags, the SDK will use a combination of the
identifier and traits to build the cache key, this ensures that the flags are refetched from the API if an identity's
traits change.

The TTL for the cache is 5 minutes, and is not configurable.

</TabItem>
<TabItem value="nodejs" label="NodeJS">

Expand Down