Software /
code /
prosody
Comparison
util/cache.lua @ 6943:0a31ec3193f0
util.cache: Make sure cache size is specified as an integer
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 25 Nov 2015 20:49:41 +0100 |
parent | 6933:d636815d81c3 |
child | 6945:d779c55058c6 |
comparison
equal
deleted
inserted
replaced
6942:f12deb882148 | 6943:0a31ec3193f0 |
---|---|
1 local cache_methods = {}; | 1 local cache_methods = {}; |
2 local cache_mt = { __index = cache_methods }; | 2 local cache_mt = { __index = cache_methods }; |
3 | 3 |
4 local function new(size) | 4 local function new(size) |
5 size = assert(tonumber(size), "cache size must be a number"); | |
6 size = math.floor(size); | |
5 assert(size > 0, "cache size must be greater than zero"); | 7 assert(size > 0, "cache size must be greater than zero"); |
6 local data = {}; | 8 local data = {}; |
7 return setmetatable({ data = data, count = 0, size = size, head = nil, tail = nil }, cache_mt); | 9 return setmetatable({ data = data, count = 0, size = size, head = nil, tail = nil }, cache_mt); |
8 end | 10 end |
9 | 11 |