NewCacheWithCapacity initializes a new caching space with the given capacity.
(capacity int)
| 46 | // NewCacheWithCapacity initializes a new caching space with the given |
| 47 | // capacity. |
| 48 | func NewCacheWithCapacity(capacity int) (*Cache, error) { |
| 49 | if capacity < 1 { |
| 50 | return nil, errors.New("Capacity must be greater than zero.") |
| 51 | } |
| 52 | |
| 53 | c := &Cache{ |
| 54 | capacity: capacity, |
| 55 | } |
| 56 | |
| 57 | c.init() |
| 58 | return c, nil |
| 59 | } |
| 60 | |
| 61 | // NewCache initializes a new caching space with default settings. |
| 62 | func NewCache() *Cache { |