예제 #1
0
//Len returns # of records in the cache.
func (c *Cache) Len() int {
	var r []*record.DB
	err := db.DB.View(func(tx *bolt.Tx) error {
		var err error
		r, err = record.GetFromDBs(tx, c.Datfile)
		return err
	})
	if err != nil {
		log.Print(err)
		return 0
	}
	return len(r)
}
예제 #2
0
//Remove Remove all files and dirs of cache.
func (c *Cache) Remove() {
	err := db.DB.Update(func(tx *bolt.Tx) error {
		r, err := record.GetFromDBs(tx, c.Datfile)
		if err != nil {
			return err
		}
		for _, rr := range r {
			rr.Del(tx)
		}
		return db.Del(tx, "thread", []byte(c.Datfile))
	})
	if err != nil {
		log.Println(err)
	}
}
예제 #3
0
//HasRecord return true if  cache has more than one records or removed records.
func (c *Cache) HasRecord() bool {
	var r []*record.DB
	err := db.DB.View(func(tx *bolt.Tx) error {
		var err error
		r, err = record.GetFromDBs(tx, c.Datfile)
		return err
	})
	if err != nil {
		log.Print(err)
		return false
	}
	for _, rr := range r {
		if !rr.Deleted {
			return true
		}
	}
	return false
}
예제 #4
0
//Velocity returns number of records in one days in the cache.
func (c *Cache) Velocity() int {
	var r []*record.DB
	err := db.DB.View(func(tx *bolt.Tx) error {
		var err error
		r, err = record.GetFromDBs(tx, c.Datfile)
		return err
	})
	if err != nil {
		log.Print(err)
		return 0
	}
	cnt := 0
	t := int64(time.Now().Add(-7 * 24 * time.Hour).Second())
	for _, rr := range r {
		if rr.Stamp > t {
			cnt++
		}
	}
	return cnt
}
예제 #5
0
//Size returns sum of body char length of records in the cache.
func (c *Cache) Size() int64 {
	if c.Len() == 0 {
		return 0
	}
	var r []*record.DB
	err := db.DB.View(func(tx *bolt.Tx) error {
		var err error
		r, err = record.GetFromDBs(tx, c.Datfile)
		return err
	})
	if err != nil {
		log.Print(err)
		return 0
	}
	var cnt int64
	for _, rr := range r {
		cnt += int64(len(rr.Body))
	}
	return cnt
}
예제 #6
0
//Stamp returns latest stampl of records in the cache.
func (c *Cache) Stamp() int64 {
	var r []*record.DB
	err := db.DB.View(func(tx *bolt.Tx) error {
		var err error
		r, err = record.GetFromDBs(tx, c.Datfile)
		return err
	})
	if err != nil {
		log.Print(err)
		return 0
	}
	if len(r) == 0 {
		return 0
	}
	var stamp int64
	for i := len(r) - 1; i >= 0; i-- {
		if !r[i].Deleted {
			stamp = r[i].Stamp
			break
		}
	}
	return stamp
}