kunt

golang IRC bot
git clone git://git.2f30.org/kunt
Log | Files | Refs | LICENSE

commit 7df47eeb5c09223759fa1f68c5200f503fed0ec8
parent 80f5a620c451f25842d994ba2b0a474c7728b5b1
Author: sin <sin@2f30.org>
Date:   Sun, 28 Apr 2013 16:03:23 +0100

mapfs: Add cacheOnly option

Diffstat:
Msrc/mapfs/mapfs.go | 29++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/mapfs/mapfs.go b/src/mapfs/mapfs.go @@ -14,11 +14,12 @@ import ( ) type Mapfs struct { - name string - path string - prefix string - dict map[int]mapfsVal - lock sync.Mutex + name string + path string + prefix string + dict map[int]mapfsVal + lock sync.Mutex + cacheOnly bool } type mapfsVal struct { @@ -28,10 +29,11 @@ type mapfsVal struct { func NewMapfs(name string, path string, prefix string) *Mapfs { return &Mapfs{ - name: name, - path: path, - prefix: prefix, - dict: make(map[int]mapfsVal), + name: name, + path: path, + prefix: prefix, + dict: make(map[int]mapfsVal), + cacheOnly: false, } } @@ -62,6 +64,9 @@ func (m *Mapfs) fsWrite(key int, buf []byte) error { func (m *Mapfs) Sync() error { m.lock.Lock() defer m.lock.Unlock() + if m.cacheOnly { + return nil + } for k, v := range m.dict { if v.dirty { err := m.fsWrite(k, v.data) @@ -76,6 +81,12 @@ func (m *Mapfs) Sync() error { return nil } +func (m *Mapfs) CacheOnly(flag bool) { + m.lock.Lock() + defer m.lock.Unlock() + m.cacheOnly = flag +} + // Print map func (m *Mapfs) String() string { m.lock.Lock()