Skip to content

Commit

Permalink
add NewInTemp func
Browse files Browse the repository at this point in the history
  • Loading branch information
kukymbr committed Mar 4, 2024
1 parent 8dd239f commit ee0803b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion filecache.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
TTLEternal = time.Duration(-1)
)

// New creates new file cache instance with a specified target dir & options.
// New creates a new FileCache instance with a specified target dir & options.
func New(targetDir string, options ...InstanceOptions) (FileCache, error) {
if len(options) > 1 {
return nil, fmt.Errorf("more than one instance options param behavior is not supported")
Expand Down Expand Up @@ -59,6 +59,11 @@ func New(targetDir string, options ...InstanceOptions) (FileCache, error) {
return fc, nil
}

// NewInTemp creates a new FileCache instance with files stored in the system's temp dir.
func NewInTemp(options ...InstanceOptions) (FileCache, error) {
return New("", options...)
}

// FileCache is a tool to cache data from any io.Reader to the file.
type FileCache interface {
// GetPath returns the target path of the FileCache instance.
Expand Down
3 changes: 3 additions & 0 deletions filecache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func TestNew_WhenValid_ExpectNoError(t *testing.T) {
func() (filecache.FileCache, error) {
return filecache.New("")
},
func() (filecache.FileCache, error) {
return filecache.NewInTemp()
},
func() (filecache.FileCache, error) {
return filecache.New("./testdata/new")
},
Expand Down

0 comments on commit ee0803b

Please sign in to comment.