transx/cache/queue.go

32 lines
539 B
Go
Raw Permalink Normal View History

2016-01-10 13:44:02 +08:00
package cache
type Cache struct {
cache []byte
l int //length of content, not length of slice.
}
type QueueCache struct { //FIFO
queue chan *Cache
}
type BlockingQueueCache QueueCache
2016-01-10 13:44:02 +08:00
func NewBlockingQueueCache(quN int) *BlockingQueueCache {
t := &BlockingQueueCache{
queue: make(chan *Cache, quN),
}
return t
}
func (this *BlockingQueueCache) Put(bits []byte, l int) {
this.queue <- &Cache{
cache: bits,
l: l,
}
}
func (this *BlockingQueueCache) Get() ([]byte, int) {
t := <-this.queue
2016-01-10 13:44:02 +08:00
return t.cache, t.l
}