Example #1
0
func main() {
	addr := flag.String("addr", ":8080", "Address to listen on")
	path := flag.String("disk", "", "Path to file to be used as persistent storage")
	flag.Parse()

	sch, err := disk.NewAIOScheduler(2048)
	if err != nil {
		panic(err)
	}

	disk, err := disk.Open(*path, sch)
	if err != nil {
		panic(err)
	}

	buckets, err := bucket.Open("/cache-buckets", disk)
	if err != nil {
		panic(err)
	}

	ht, err := hashtable.Open("/cache-hashtable")
	if err != nil {
		panic(err)
	}

	srv := Server{
		cache: cache.New(ht, buckets),
	}

	http.HandleFunc("/", srv.handler)
	http.ListenAndServe(*addr, nil)
}
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)
}