feat(server): allow cacheable paths to be configured in router
This commit is contained in:
@@ -27,6 +27,7 @@ type RouterConfig struct {
|
|||||||
Debug bool
|
Debug bool
|
||||||
DisableCache bool
|
DisableCache bool
|
||||||
DisableCompression bool
|
DisableCompression bool
|
||||||
|
CacheablePaths []string
|
||||||
DBMonitor middleware.DBMonitor
|
DBMonitor middleware.DBMonitor
|
||||||
RateLimitConfig config.RateLimitConfig
|
RateLimitConfig config.RateLimitConfig
|
||||||
}
|
}
|
||||||
@@ -49,6 +50,9 @@ func NewRouter(cfg RouterConfig) http.Handler {
|
|||||||
if !cfg.DisableCache {
|
if !cfg.DisableCache {
|
||||||
cache := middleware.NewInMemoryCache()
|
cache := middleware.NewInMemoryCache()
|
||||||
cacheConfig := middleware.DefaultCacheConfig()
|
cacheConfig := middleware.DefaultCacheConfig()
|
||||||
|
if len(cfg.CacheablePaths) > 0 {
|
||||||
|
cacheConfig.CacheablePaths = append([]string{}, cfg.CacheablePaths...)
|
||||||
|
}
|
||||||
router.Use(middleware.CacheMiddleware(cache, cacheConfig))
|
router.Use(middleware.CacheMiddleware(cache, cacheConfig))
|
||||||
router.Use(middleware.CacheInvalidationMiddleware(cache))
|
router.Use(middleware.CacheInvalidationMiddleware(cache))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user