Ejemplo n.º 1
0
// NewDriver instantiate a new cache driver
func NewDriver(maxSize uint64, expiration time.Duration) (drivers.Driver, error) {
	cache := new(cacheDriver)
	cache.storedBuckets = make(map[string]storedBucket)
	cache.objects = trove.NewCache(maxSize, expiration)
	cache.maxSize = maxSize
	cache.expiration = expiration
	cache.multiPartObjects = trove.NewCache(0, time.Duration(0))
	cache.lock = new(sync.RWMutex)

	cache.objects.OnExpired = cache.expiredObject
	cache.multiPartObjects.OnExpired = cache.expiredPart

	// set up cache expiration
	cache.objects.ExpireObjects(time.Second * 5)
	return cache, nil
}
Ejemplo n.º 2
0
// NewDriver instantiate a donut driver
func NewDriver(paths []string, maxSize uint64, expiration time.Duration) (drivers.Driver, error) {
	driver := new(donutDriver)
	driver.storedBuckets = make(map[string]storedBucket)
	driver.objects = trove.NewCache(maxSize, expiration)
	driver.maxSize = maxSize
	driver.expiration = expiration
	driver.multiPartObjects = trove.NewCache(0, time.Duration(0))
	driver.lock = new(sync.RWMutex)

	driver.objects.OnExpired = driver.expiredObject
	driver.multiPartObjects.OnExpired = driver.expiredPart

	// set up memory expiration
	driver.objects.ExpireObjects(time.Second * 5)

	driver.paths = paths
	driver.lock = new(sync.RWMutex)

	err := initialize(driver)
	return driver, err
}