Example #1
0
func main() {
	defaultSize := bucket.BucketSize * uint64(bucket.MaxOpen)

	path := flag.String("disk", "", "File path to setup as persistent storage")
	size := flag.Uint64("size", defaultSize, "Size of persistent storage")
	flag.Parse()

	f, err := os.Create(*path)
	if err != nil {
		panic(err)
	}
	defer f.Close()

	err = f.Truncate(int64(*size))
	if err != nil {
		panic(err)
	}

	err = bucket.Create("/cache-buckets", *size)
	if err != nil {
		panic(err)
	}

	// We expect values to be at least 1KB
	err = hashtable.Create("/cache-hashtable", *size/1024)
	if err != nil {
		panic(err)
	}
}
Example #2
0
func (s *CacheSuite) SetUpTest(c *C) {
	diskSize := int(4096 * bucket.BucketSize)
	disk := disk.NewMockDisk(diskSize)
	err := bucket.Create("/test-cache-bucket", uint64(diskSize))
	c.Assert(err, IsNil)

	s.buckets, err = bucket.Open("/test-cache-bucket", disk)
	c.Assert(err, IsNil)

	err = hashtable.Create("/test-cache-ht", 2048)
	c.Assert(err, IsNil)

	s.ht, err = hashtable.Open("/test-cache-ht")
	c.Assert(err, IsNil)

	s.cache = New(s.ht, s.buckets)
}