Skip to content

Commit

Permalink
added clean cache API
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuelef committed Sep 23, 2023
1 parent 2e47ccb commit 006353e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ func (c *Cache[T]) Get(key string) (T, bool) {
return item.Value, true
}

func (c *Cache[T]) Reset() {
c.mu.Lock()
defer c.mu.Unlock()
c.items = make(map[string]CacheItem[T])
}

func main() {
ctx := context.Background()
tp, exp, err := otel_instrumentation.InitializeGlobalTracerProvider(ctx)
Expand Down Expand Up @@ -223,6 +229,12 @@ func main() {
return c.JSON(res)
})

app.Post("/cleanAllCache", func(c *fiber.Ctx) error {
cache.Reset()
cacheStars.Reset()
return c.Send(nil)
})

host := getEnv("HOST", "localhost")
port := getEnv("PORT", "8080")
hostAddress := fmt.Sprintf("%s:%s", host, port)
Expand Down

0 comments on commit 006353e

Please sign in to comment.