Spaces:
Paused
Paused
ML Intern deploy
Deploy httpSMS gateway to Hugging Face Spaces (Docker SDK): nginx :7860 -> Go API :8000, Nuxt SPA, Android APK, bootstrap-mode entrypoint
83a59ca Download api/pkg/cache/memory_cache.go from red-kit/httpsms-gateway: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/83a59cae175e3c9a43b6f5d3f8749ca61b6b5072/api/pkg/cache/memory_cache.go
- Command line
-
hf download hf://spaces/red-kit/httpsms-gateway@83a59cae175e3c9a43b6f5d3f8749ca61b6b5072/api/pkg/cache/memory_cache.go
-
curl -L -o memory_cache.go https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/83a59cae175e3c9a43b6f5d3f8749ca61b6b5072/api/pkg/cache/memory_cache.go
1.09 kB
| package cache | |
| import ( | |
| "context" | |
| "time" | |
| "github.com/NdoleStudio/httpsms/pkg/telemetry" | |
| "github.com/NdoleStudio/stacktrace" | |
| ttlCache "github.com/patrickmn/go-cache" | |
| ) | |
| // memoryCache is the Cache implementation in memory | |
| type memoryCache struct { | |
| tracer telemetry.Tracer | |
| store *ttlCache.Cache | |
| } | |
| // NewMemoryCache creates a new instance of memoryCache | |
| func NewMemoryCache(tracer telemetry.Tracer, store *ttlCache.Cache) Cache { | |
| return &memoryCache{ | |
| tracer: tracer, | |
| store: store, | |
| } | |
| } | |
| // Get an item from the redis cache | |
| func (cache *memoryCache) Get(ctx context.Context, key string) (value string, err error) { | |
| ctx, span := cache.tracer.Start(ctx) | |
| defer span.End() | |
| response, ok := cache.store.Get(key) | |
| if !ok { | |
| return "", stacktrace.NewErrorf("no item found in cache with key [%s]", key) | |
| } | |
| return response.(string), nil | |
| } | |
| // Set an item in the redis cache | |
| func (cache *memoryCache) Set(ctx context.Context, key string, value string, ttl time.Duration) error { | |
| ctx, span := cache.tracer.Start(ctx) | |
| defer span.End() | |
| cache.store.Set(key, value, ttl) | |
| return nil | |
| } | |