Skip to content

Commit

Permalink
update cache driver
Browse files Browse the repository at this point in the history
  • Loading branch information
kkumar-gcc committed Oct 6, 2024
1 parent 4d93eb2 commit 6af8080
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions cache/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ type Application struct {
cache.Driver
config config.Config
log log.Log
driver *Driver
stores map[string]cache.Driver
}

func NewApplication(config config.Config, log log.Log, store string) (*Application, error) {
driver := NewDriverImpl(config)
driver := NewDriver(config)
instance, err := driver.New(store)
if err != nil {
return nil, err
Expand All @@ -24,6 +25,7 @@ func NewApplication(config config.Config, log log.Log, store string) (*Applicati
Driver: instance,
config: config,
log: log,
driver: driver,
stores: map[string]cache.Driver{
store: instance,
},
Expand All @@ -35,8 +37,7 @@ func (app *Application) Store(name string) cache.Driver {
return driver
}

driver := NewDriverImpl(app.config)
instance, err := driver.New(name)
instance, err := app.driver.New(name)
if err != nil {
app.log.Error(err)

Expand Down
12 changes: 6 additions & 6 deletions cache/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import (
"github.com/goravel/framework/errors"
)

type DriverImpl struct {
type Driver struct {
config config.Config
}

func NewDriverImpl(config config.Config) *DriverImpl {
return &DriverImpl{
func NewDriver(config config.Config) *Driver {
return &Driver{
config: config,
}
}

func (d *DriverImpl) New(store string) (cache.Driver, error) {
func (d *Driver) New(store string) (cache.Driver, error) {
driver := d.config.GetString(fmt.Sprintf("cache.stores.%s.driver", store))
switch driver {
case "memory":
Expand All @@ -30,11 +30,11 @@ func (d *DriverImpl) New(store string) (cache.Driver, error) {
}
}

func (d *DriverImpl) memory() (cache.Driver, error) {
func (d *Driver) memory() (cache.Driver, error) {
return NewMemory(d.config)
}

func (d *DriverImpl) custom(store string) (cache.Driver, error) {
func (d *Driver) custom(store string) (cache.Driver, error) {
if custom, ok := d.config.Get(fmt.Sprintf("cache.stores.%s.via", store)).(cache.Driver); ok {
return custom, nil
}
Expand Down

0 comments on commit 6af8080

Please sign in to comment.