Skip to content

Commit

Permalink
switch to go 1.23
Browse files Browse the repository at this point in the history
refactoring
add context passing everywhere
add new caching logic
  • Loading branch information
vintikzzz committed Nov 5, 2024
1 parent 3f31993 commit ebf6df6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions services/cache_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"net/http"
"net/url"
"time"
)

type CacheMap struct {
Expand All @@ -15,13 +16,16 @@ type CacheMap struct {

func NewCacheMap(cl *http.Client) *CacheMap {
return &CacheMap{
LazyMap: lazymap.New(&lazymap.Config{}),
cl: cl,
LazyMap: lazymap.New(&lazymap.Config{
Expire: 30 * time.Second,
ErrorExpire: 5 * time.Second,
}),
cl: cl,
}
}

func (s *CacheMap) Get(ctx context.Context, url *MyURL) (bool, error) {
res, err := s.LazyMap.Get("", func() (interface{}, error) {
res, err := s.LazyMap.Get(url.String(), func() (interface{}, error) {
return s.get(ctx, url)
})
if err != nil {
Expand Down

0 comments on commit ebf6df6

Please sign in to comment.