Skip to content

Commit

Permalink
Merge pull request #10 from waynezhang/develop
Browse files Browse the repository at this point in the history
fix: handle singleton in cache properly
  • Loading branch information
waynezhang authored Feb 7, 2024
2 parents d6065bc + fe7d2ba commit d9e9577
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
7 changes: 7 additions & 0 deletions internal/cache/cache.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cache

import (
"sync"

"github.com/waynezhang/foto/internal/constants"
)

Expand All @@ -10,6 +12,11 @@ type Cache interface {
Clear()
}

var (
once sync.Once
instance Cache
)

func Shared() Cache {
once.Do(func() {
instance = NewFolderCache(constants.CacheDirectoryName)
Expand Down
9 changes: 1 addition & 8 deletions internal/cache/file_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cache
import (
"fmt"
"path/filepath"
"sync"

cp "github.com/otiai10/copy"
"github.com/rs/zerolog/log"
Expand All @@ -16,16 +15,10 @@ type folderCache struct {
directoryName string
}

var (
once sync.Once
instance Cache
)

func NewFolderCache(directoryName string) Cache {
instance = folderCache{
return folderCache{
directoryName: directoryName,
}
return instance
}

// `src` is used to compute checksum, `file` will be copied to the cache
Expand Down

0 comments on commit d9e9577

Please sign in to comment.