32 lines
539 B
Go
32 lines
539 B
Go
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
|
|
|
|
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
|
|
return t.cache, t.l
|
|
}
|