Skip to content

Commit

Permalink
Merge pull request #7 from FrosTiK-SD/bigcache
Browse files Browse the repository at this point in the history
Added bigcache initialization
  • Loading branch information
dev-raj-1729 authored Jan 28, 2024
2 parents a6e639b + 3f55547 commit b6d670b
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ func NewClient(mongoURL string, config *mongik.Config) *mongik.Mongik {
log.Println("Connected to MongoDB")
}

// Initialize BigCache anyway
cacheClient, _ := bigcache.New(context.Background(), bigcache.DefaultConfig(config.TTL))

// Check for caching mode
if config.Client == constants.REDIS {
// Check for default redisConfig
Expand All @@ -38,8 +41,6 @@ func NewClient(mongoURL string, config *mongik.Config) *mongik.Mongik {
})
if err := redisClient.Ping(context.Background()).Err(); err != nil {
if config.FallbackToDefault == true {
// Initialize BigCache
cacheClient, _ := bigcache.New(context.Background(), bigcache.DefaultConfig(config.TTL))
return &mongik.Mongik{
MongoClient: mongoClient,
CacheClient: cacheClient,
Expand All @@ -56,21 +57,14 @@ func NewClient(mongoURL string, config *mongik.Config) *mongik.Mongik {
return &mongik.Mongik{
MongoClient: mongoClient,
RedisClient: redisClient,
Config: config,
}

} else if config.Client == constants.BIGCACHE {
// Initialize BigCache
cacheClient, _ := bigcache.New(context.Background(), bigcache.DefaultConfig(config.TTL))
return &mongik.Mongik{
MongoClient: mongoClient,
CacheClient: cacheClient,
Config: config,
}
}

return &mongik.Mongik{
MongoClient: mongoClient,
CacheClient: cacheClient,
Config: config,
}
}

0 comments on commit b6d670b

Please sign in to comment.