MCPcopy Create free account
hub / github.com/ContentSquare/chproxy / newFilesSystemCache

Function newFilesSystemCache

cache/filesystem_cache.go:37–71  ·  view source on GitHub ↗

newFilesSystemCache returns new cache for the given cfg.

(cfg config.Cache, graceTime time.Duration)

Source from the content-addressed store, hash-verified

35
36// newFilesSystemCache returns new cache for the given cfg.
37func newFilesSystemCache(cfg config.Cache, graceTime time.Duration) (*fileSystemCache, error) {
38 if len(cfg.FileSystem.Dir) == 0 {
39 return nil, fmt.Errorf("`dir` cannot be empty")
40 }
41 if cfg.FileSystem.MaxSize <= 0 {
42 return nil, fmt.Errorf("`max_size` must be positive")
43 }
44 if cfg.Expire <= 0 {
45 return nil, fmt.Errorf("`expire` must be positive")
46 }
47
48 c := &fileSystemCache{
49 name: cfg.Name,
50
51 dir: cfg.FileSystem.Dir,
52 maxSize: uint64(cfg.FileSystem.MaxSize),
53 expire: time.Duration(cfg.Expire),
54 grace: graceTime,
55 stopCh: make(chan struct{}),
56 }
57
58 if err := os.MkdirAll(c.dir, 0700); err != nil {
59 return nil, fmt.Errorf("cannot create %q: %w", c.dir, err)
60 }
61
62 c.wg.Add(1)
63 go func() {
64 log.Debugf("cache %q: cleaner start", c.Name())
65 c.cleaner()
66 log.Debugf("cache %q: cleaner stop", c.Name())
67 c.wg.Done()
68 }()
69
70 return c, nil
71}
72
73func (f *fileSystemCache) Name() string {
74 return f.name

Callers 4

NewAsyncCacheFunction · 0.85
newAsyncTestCacheFunction · 0.85
TestCacheCleanFunction · 0.85
newTestCacheFunction · 0.85

Calls 3

NameMethod · 0.95
cleanerMethod · 0.95
DebugfFunction · 0.92

Tested by 3

newAsyncTestCacheFunction · 0.68
TestCacheCleanFunction · 0.68
newTestCacheFunction · 0.68