func (l *lru) AllCacheHits() uint64 {
	return l.allCacheHits()
}
AllCacheHits returns cache hits across all metrics.
package strategy
import (
	"time"
	"github.com/intelsdi-x/snap/core"
	log "github.com/sirupsen/logrus"
)
type lru struct {
	*cache
	logger *log.Entry
}
func NewLRU(cacheTTL time.Duration) *lru {
	return &lru{
		NewCache(cacheTTL),
		log.WithFields(log.Fields{
			"_module": "control-routing",
		}),
	}
}
func (l *lru) String() string {
	return "least-recently-used"
}
func (l *lru) CacheTTL(taskID string) (time.Duration, error) {
	return l.ttl, nil
}
func (l *lru) Select(aps []AvailablePlugin, _ string) (AvailablePlugin, error) {
	t := time.Now()
	index := -1
	for i, ap := range aps {
		if ap.LastHit().Before(t) || index == -1 {
			index = i
			t = ap.LastHit()
		}
	}
	if index > -1 {
		l.logger.WithFields(log.Fields{
			"block":     "select",
			"strategy":  l.String(),
			"pool size": len(aps),
			"index":     aps[index].String(),
			"hitcount":  aps[index].HitCount(),
		}).Debug("plugin selected")
		return aps[index], nil
	}
	l.logger.WithFields(log.Fields{
		"block":    "select",
		"strategy": l.String(),
		"error":    ErrCouldNotSelect,
	}).Error("error selecting")
	return nil, ErrCouldNotSelect
}
func (l *lru) Remove(aps []AvailablePlugin, taskID string) (AvailablePlugin, error) {
	ap, err := l.Select(aps, taskID)
	if err != nil {
		return nil, err
	}
	return ap, nil
}
func (l *lru) CheckCache(mts []core.Metric, _ string) ([]core.Metric, []core.Metric) {
	return l.checkCache(mts)
}
func (l *lru) UpdateCache(mts []core.Metric, _ string) {
	l.updateCache(mts)
}