Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammad362 committed Nov 29, 2023
1 parent 88bb330 commit 9ce655b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions config.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ webp:
# Caching Settings
cache:
expiration_minutes: 60 # Cache expiration time in minutes
cleanup_interval_minutes: 120 # Cache cleanup interval in minutes
cache_enabled: false
cache_enabled: true
nocache_header: "X-No-Cache" # You can change the header name as needed
lru_cache: 300000

# Concurrency Settings
concurrency:
Expand All @@ -29,4 +29,4 @@ http_client:
TLS_handshake_timeout: 10
response_header_timeout: 30
expect_continue_timeout: 1
idle_conn_timeout: 90
idle_conn_timeout: 90
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ require (
github.com/spf13/viper v1.17.0
)

require github.com/hashicorp/golang-lru/v2 v2.0.7

require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down
18 changes: 7 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

"github.com/gorilla/mux"
"github.com/h2non/bimg"
lru "github.com/hashicorp/golang-lru"
"github.com/hashicorp/golang-lru/v2/expirable"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
Expand All @@ -29,10 +29,10 @@ type Config struct {
NearLossless int `mapstructure:"near_lossless"`
} `mapstructure:"webp"`
Cache struct {
ExpirationMinutes int `mapstructure:"expiration_minutes"`
CleanupIntervalMinutes int `mapstructure:"cleanup_interval_minutes"`
CacheEnabled bool `mapstructure:"cache_enabled"`
NoCacheHeader string `mapstructure:"nocache_header"`
ExpirationMinutes int `mapstructure:"expiration_minutes"`
CacheEnabled bool `mapstructure:"cache_enabled"`
NoCacheHeader string `mapstructure:"nocache_header"`
LruCache int `mapstructure:"lru_cache"`
} `mapstructure:"cache"`
Concurrency struct {
MaxGoroutines int `mapstructure:"max_goroutines"`
Expand All @@ -55,7 +55,7 @@ type ImageResult struct {

var (
config Config
imgCache *lru.Cache
imgCache *expirable.LRU[string, []byte]
logger *logrus.Logger
httpClient *http.Client
semaphore chan struct{}
Expand All @@ -73,11 +73,7 @@ func init() {
logrus.Fatalf("Unable to decode into struct: %v", err)
}

var err error
imgCache, err = lru.New(128) // Adjust the size as needed
if err != nil {
logrus.Fatalf("Failed to create LRU cache: %v", err)
}
imgCache = expirable.NewLRU[string, []byte](config.Cache.LruCache, nil, time.Duration(config.Cache.ExpirationMinutes)*time.Minute)

logger = logrus.New()
logger.Out = os.Stdout
Expand Down

0 comments on commit 9ce655b

Please sign in to comment.