Skip to content

Commit

Permalink
add support for local cache manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishwas Shashidhar committed Apr 24, 2023
1 parent 34899a8 commit b3c5f44
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 92 deletions.
4 changes: 4 additions & 0 deletions cache/cache_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
const DependencyCacheManager = "cache_manager"

const ProviderRedis = "REDIS"
const ProviderLocal = "LOCAL"

type Manager interface {
// GetStatus ... Returns the current status of the cache system connection
Expand All @@ -33,6 +34,9 @@ func Bootstrap(provider string) {
sm: c.Get(secrets.DependencySecretsManager).(secrets.Manager),
}
r.(*redisCacheManager).initialize()
case ProviderLocal:
r = &localCacheManager{}
r.(*localCacheManager).initialize()
default:
err := errors.New("cache provider not implemented")
logger.Log.Fatal().Err(err).Str("provider", provider)
Expand Down
25 changes: 25 additions & 0 deletions cache/local_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cache

type localCacheManager struct {
store map[string]interface{}
}

func (r *localCacheManager) initialize() {
r.store = make(map[string]interface{})
}

func (r *localCacheManager) GetStatus() string {
return "UP"
}

func (r *localCacheManager) Set(key string, val interface{}) error {
r.store[key] = val
return nil
}

func (r *localCacheManager) Get(key string) (string, error) {
if r.store[key] == nil {
return "", nil
}
return r.store[key].(string), nil
}
46 changes: 46 additions & 0 deletions cache/local_manager_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cache

import (
"github.com/adwitiyaio/arka/config"
"github.com/adwitiyaio/arka/constants"
"github.com/adwitiyaio/arka/dependency"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"testing"
)

type LocalManagerTestSuite struct {
suite.Suite
ccm Manager
}

func TestLocalManager(t *testing.T) {
suite.Run(t, new(LocalManagerTestSuite))
}

func (ts *LocalManagerTestSuite) SetupSuite() {
dm := dependency.GetManager()
config.Bootstrap(config.ProviderEnvironment, "../test.env")
Bootstrap(ProviderLocal)
ts.ccm = dm.Get(DependencyCacheManager).(Manager)
}

func (ts *LocalManagerTestSuite) Test_localCacheManager_GetStatus() {
ts.Run("success", func() {
status := ts.ccm.GetStatus()
assert.Equal(ts.T(), constants.SystemStatusUp, status)
})
}

func (ts *LocalManagerTestSuite) Test_localCacheManager_Set_Get() {
ts.Run("success", func() {
key := "test_key"
val := "Test Value"
err := ts.ccm.Set(key, val)
require.NoError(ts.T(), err)
result, err := ts.ccm.Get(key)
require.NoError(ts.T(), err)
assert.Equal(ts.T(), val, result)
})
}
40 changes: 24 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/adwitiyaio/arka
go 1.20

require (
firebase.google.com/go/v4 v4.6.1
firebase.google.com/go/v4 v4.10.0
github.com/OneSignal/onesignal-go-api v1.0.4
github.com/Uchencho/go-termii v1.0.2
github.com/aws/aws-sdk-go-v2 v1.17.5
Expand All @@ -25,16 +25,21 @@ require (
github.com/nyaruka/phonenumbers v1.0.69
github.com/robfig/cron/v3 v3.0.0
github.com/rs/zerolog v1.22.0
github.com/stretchr/testify v1.8.0
github.com/stretchr/testify v1.8.1
github.com/stripe/stripe-go/v72 v72.51.0
github.com/xuri/excelize/v2 v2.4.1
google.golang.org/api v0.40.0
google.golang.org/api v0.103.0
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
gorm.io/driver/postgres v1.4.7
gorm.io/gorm v1.24.5
)

require (
cloud.google.com/go/compute v1.14.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.7.0 // indirect
cloud.google.com/go/longrunning v0.3.0 // indirect
github.com/MicahParks/keyfunc v1.5.1 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.22 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.29 // indirect
Expand All @@ -49,19 +54,26 @@ require (
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.18.3 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
github.com/jackc/pgx/v5 v5.2.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/time v0.1.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine/v2 v2.0.2 // indirect
)

require (
cloud.google.com/go v0.75.0 // indirect
cloud.google.com/go/firestore v1.5.0 // indirect
cloud.google.com/go/storage v1.10.0 // indirect
cloud.google.com/go v0.105.0 // indirect
cloud.google.com/go/firestore v1.9.0 // indirect
cloud.google.com/go/storage v1.27.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ses v1.15.1
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
Expand All @@ -72,7 +84,6 @@ require (
github.com/jinzhu/now v1.1.5 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.10 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
Expand All @@ -84,19 +95,16 @@ require (
github.com/richardlehane/mscfb v1.0.3 // indirect
github.com/richardlehane/msoleps v1.0.1 // indirect
github.com/xuri/efp v0.0.0-20210322160811-ab561f5b45e3 // indirect
go.opencensus.io v0.22.5 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.4.0 // indirect
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/tools v0.1.12 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210222152913-aa3ee6e6a81c // indirect
google.golang.org/grpc v1.35.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
google.golang.org/genproto v0.0.0-20221202195650-67e5cbc046fd // indirect
google.golang.org/grpc v1.50.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit b3c5f44

Please sign in to comment.