From 989a5c381b6803f1c7b7350c0b1062f58ab3304b Mon Sep 17 00:00:00 2001 From: Jamil Najafov Date: Tue, 18 Oct 2022 13:20:16 +0300 Subject: [PATCH 1/2] PA-18272 Updated Inscacheable Added Exists and Delete (#1) --- inscacheable/cacheable.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/inscacheable/cacheable.go b/inscacheable/cacheable.go index cac1c0e..6ea4459 100644 --- a/inscacheable/cacheable.go +++ b/inscacheable/cacheable.go @@ -8,20 +8,36 @@ import ( type Cacher[K comparable, V any] interface { Get(k K) V Set(k K, v V, ttl time.Duration) + Exists(k K) bool + Delete(k K) } type Cache[K comparable, V any] struct { cache *ttlcache.Cache[K, V] } +// Get returns a value at the given key. +// It is non-null safe method, so be sure to use Exists before getting the value. func (c *Cache[K, V]) Get(k K) V { return c.cache.Get(k).Value() } +// Set stores the value at the given key. +// It accepts ttl=0 that indicates the default TTL given at initialization should be used. func (c *Cache[K, V]) Set(k K, v V, ttl time.Duration) { c.cache.Set(k, v, ttl) } +// Exists checks if key is set in the cache. +func (c *Cache[K, V]) Exists(k K) bool { + return c.cache.Get(k) != nil +} + +// Delete deletes the key from the cache. +func (c *Cache[K, V]) Delete(k K) { + c.cache.Delete(k) +} + // Cacheable is the main function that should be used as // func getter(key string) string { ... the original getter function ... } // var ttl = 1 * time.Minute @@ -54,6 +70,10 @@ func makeCache[K comparable, V any](ttl *time.Duration, loader ttlcache.LoaderFu } func makeLoader[K comparable, V any](getter func(key K) V) ttlcache.LoaderFunc[K, V] { + if getter == nil { + return nil + } + fn := func(c *ttlcache.Cache[K, V], key K) *ttlcache.Item[K, V] { var v = getter(key) From f45756a789a5000d08262a720516fdf795350ca0 Mon Sep 17 00:00:00 2001 From: insider-it Date: Thu, 20 Oct 2022 19:11:49 +0300 Subject: [PATCH 2/2] new workflow added --- .github/workflows/cxflow.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .github/workflows/cxflow.yml diff --git a/.github/workflows/cxflow.yml b/.github/workflows/cxflow.yml new file mode 100644 index 0000000..e69de29