Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go-fuse
Commits
e36affb8
Commit
e36affb8
authored
Nov 04, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only cache successful results indefinitely in CachingFileSystem.
parent
eb06cb23
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
12 deletions
+46
-12
unionfs/cachingfs.go
unionfs/cachingfs.go
+15
-5
unionfs/timedcache.go
unionfs/timedcache.go
+7
-4
unionfs/timedcache_test.go
unionfs/timedcache_test.go
+23
-2
unionfs/unionfs.go
unionfs/unionfs.go
+1
-1
No files found.
unionfs/cachingfs.go
View file @
e36affb8
...
...
@@ -89,11 +89,21 @@ func readLink(fs fuse.FileSystem, name string) *linkResponse {
func
NewCachingFileSystem
(
fs
fuse
.
FileSystem
,
ttlNs
int64
)
*
CachingFileSystem
{
c
:=
new
(
CachingFileSystem
)
c
.
FileSystem
=
fs
c
.
attributes
=
NewTimedCache
(
func
(
n
string
)
interface
{}
{
return
getAttr
(
fs
,
n
)
},
ttlNs
)
c
.
dirs
=
NewTimedCache
(
func
(
n
string
)
interface
{}
{
return
readDir
(
fs
,
n
)
},
ttlNs
)
c
.
links
=
NewTimedCache
(
func
(
n
string
)
interface
{}
{
return
readLink
(
fs
,
n
)
},
ttlNs
)
c
.
xattr
=
NewTimedCache
(
func
(
n
string
)
interface
{}
{
return
getXAttr
(
fs
,
n
)
c
.
attributes
=
NewTimedCache
(
func
(
n
string
)
(
interface
{},
bool
)
{
a
:=
getAttr
(
fs
,
n
)
return
a
,
a
.
Ok
()
},
ttlNs
)
c
.
dirs
=
NewTimedCache
(
func
(
n
string
)
(
interface
{},
bool
)
{
d
:=
readDir
(
fs
,
n
)
return
d
,
d
.
Ok
()
},
ttlNs
)
c
.
links
=
NewTimedCache
(
func
(
n
string
)
(
interface
{},
bool
)
{
l
:=
readLink
(
fs
,
n
)
return
l
,
l
.
Ok
()
},
ttlNs
)
c
.
xattr
=
NewTimedCache
(
func
(
n
string
)
(
interface
{},
bool
)
{
l
:=
getXAttr
(
fs
,
n
)
return
l
,
l
.
Ok
()
},
ttlNs
)
return
c
}
...
...
unionfs/timedcache.go
View file @
e36affb8
...
...
@@ -19,8 +19,9 @@ type cacheEntry struct {
// thread-safe. Calls of fetch() do no happen inside a critical
// section, so when multiple concurrent Get()s happen for the same
// key, multiple fetch() calls may be issued for the same key.
type
TimedCacheFetcher
func
(
name
string
)
(
value
interface
{},
cacheable
bool
)
type
TimedCache
struct
{
fetch
func
(
name
string
)
interface
{}
fetch
TimedCacheFetcher
// ttlNs is a duration of the cache.
ttlNs
int64
...
...
@@ -35,7 +36,7 @@ const layerCacheTimeoutNs = 1e9
// Creates a new cache with the given TTL. If TTL <= 0, the caching is
// indefinite.
func
NewTimedCache
(
fetcher
func
(
name
string
)
interface
{}
,
ttlNs
int64
)
*
TimedCache
{
func
NewTimedCache
(
fetcher
TimedCacheFetcher
,
ttlNs
int64
)
*
TimedCache
{
l
:=
new
(
TimedCache
)
l
.
ttlNs
=
ttlNs
l
.
fetch
=
fetcher
...
...
@@ -73,8 +74,10 @@ func (me *TimedCache) DropEntry(name string) {
}
func
(
me
*
TimedCache
)
GetFresh
(
name
string
)
interface
{}
{
data
:=
me
.
fetch
(
name
)
me
.
Set
(
name
,
data
)
data
,
ok
:=
me
.
fetch
(
name
)
if
ok
{
me
.
Set
(
name
,
data
)
}
return
data
}
...
...
unionfs/timedcache_test.go
View file @
e36affb8
...
...
@@ -10,12 +10,33 @@ import (
var
_
=
fmt
.
Print
var
_
=
log
.
Print
func
TestTimedCacheUncacheable
(
t
*
testing
.
T
)
{
fetchCount
:=
0
fetch
:=
func
(
n
string
)
(
interface
{},
bool
)
{
fetchCount
++
i
:=
int
(
n
[
0
])
return
&
i
,
false
}
cache
:=
NewTimedCache
(
fetch
,
0
)
v
:=
cache
.
Get
(
"n"
)
.
(
*
int
)
w
:=
cache
.
Get
(
"n"
)
.
(
*
int
)
if
*
v
!=
int
(
'n'
)
||
*
w
!=
*
v
{
t
.
Errorf
(
"value mismatch: got %d, %d want %d"
,
*
v
,
*
w
,
int
(
'n'
))
}
if
fetchCount
!=
2
{
t
.
Fatalf
(
"Should have fetched twice: %d"
,
fetchCount
)
}
}
func
TestTimedCache
(
t
*
testing
.
T
)
{
fetchCount
:=
0
fetch
:=
func
(
n
string
)
interface
{}
{
fetch
:=
func
(
n
string
)
(
interface
{},
bool
)
{
fetchCount
++
i
:=
int
(
n
[
0
])
return
&
i
return
&
i
,
true
}
var
ttl
int64
...
...
unionfs/unionfs.go
View file @
e36affb8
...
...
@@ -97,7 +97,7 @@ func NewUnionFs(fileSystems []fuse.FileSystem, options UnionFsOptions) *UnionFs
g
.
deletionCache
=
NewDirCache
(
writable
,
options
.
DeletionDirName
,
int64
(
options
.
DeletionCacheTTLSecs
*
1e9
))
g
.
branchCache
=
NewTimedCache
(
func
(
n
string
)
interface
{}
{
return
g
.
getBranchAttrNoCache
(
n
)
},
func
(
n
string
)
(
interface
{},
bool
)
{
return
g
.
getBranchAttrNoCache
(
n
),
true
},
int64
(
options
.
BranchCacheTTLSecs
*
1e9
))
g
.
branchCache
.
RecurringPurge
()
return
g
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment