1
// Copyright 2018 The CubeFS Authors.
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
// implied. See the License for the specific language governing
13
// permissions and limitations under the License.
22
// DentryCache defines the dentry cache.
23
type DentryCache struct {
25
cache map[string]uint64
29
// NewDentryCache returns a new dentry cache.
30
func NewDentryCache() *DentryCache {
32
cache: make(map[string]uint64),
33
expiration: time.Now().Add(DentryValidDuration),
37
// Put puts an item into the cache.
38
func (dc *DentryCache) Put(name string, ino uint64) {
45
dc.expiration = time.Now().Add(DentryValidDuration)
48
// Get gets the item from the cache based on the given key.
49
func (dc *DentryCache) Get(name string) (uint64, bool) {
56
if dc.expiration.Before(time.Now()) {
57
dc.cache = make(map[string]uint64)
60
ino, ok := dc.cache[name]
64
// Delete deletes the item based on the given key.
65
func (dc *DentryCache) Delete(name string) {
71
delete(dc.cache, name)