https://github.com/onsdigital/dp-frontend-cache-helper
Helps you cache data for dp-renderer in your frontends.
https://github.com/onsdigital/dp-frontend-cache-helper
Last synced: 5 months ago
JSON representation
Helps you cache data for dp-renderer in your frontends.
- Host: GitHub
- URL: https://github.com/onsdigital/dp-frontend-cache-helper
- Owner: ONSdigital
- License: mit
- Created: 2023-02-02T16:19:27.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-11-24T11:55:09.000Z (7 months ago)
- Last Synced: 2025-11-28T01:18:57.391Z (7 months ago)
- Language: Go
- Size: 58.6 KB
- Stars: 0
- Watchers: 9
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# dp-frontend-cache-helper
Helps you cache data for dp-renderer in your frontends.
Bootstrap example:
```
cacheHelper "github.com/ONSdigital/dp-frontend-cache-helper/pkg/navigation/helper"
navCache, err := cacheHelper.Init(ctx, cacheHelper.Config{
APIRouterURL: cfg.APIRouterURL, // API Router URL
CacheUpdateInterval: cfg.CacheUpdateInterval, // 0 means update at startup only. Time in minutes.
EnableNewNavBar: cfg.EnableNewNavBar, // Used to turn on/off.
EnableCensusTopicSubsection: cfg.EnableCensusTopicSubsection, // Whether to include centus topic subsection.
CensusTopicID: cfg.CensusTopicID, // Navigation is tied to 4445 in sandbox.
IsPublishingMode: cfg.IsPublishingMode, // Whether not we're in the public subnet.
Languages: cfg.SupportedLanguages, // Usually []string{"en", "cy"}; English and Welsh
ServiceAuthToken: cfg.ServiceAuthToken, // Service to Service Auth token. Required for publishing subnet.
})
// Starts the background jobs.
navCache.RunUpdates(ctx, svcErrors)
```
Then within your handlers:
```
mappedNavContent, err := navCache.GetMappedNavigationContent(ctx, lang)
if err != nil && navCache.Config.EnableNewNavBar == true {
model.NavigationContent = mappedNavContent
}
```