Mercurial > prosody-hg
comparison util/cache.lua @ 8396:fbe1f99fb245
util.cache: Add method for removing all data (does not call eviction callback)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 07 Nov 2017 00:38:47 +0100 |
| parents | 9385c367e920 |
| children | 99d85731e3ee |
comparison
equal
deleted
inserted
replaced
| 8395:fbb9a1c2120e | 8396:fbe1f99fb245 |
|---|---|
| 137 }); | 137 }); |
| 138 end | 138 end |
| 139 return self.proxy_table; | 139 return self.proxy_table; |
| 140 end | 140 end |
| 141 | 141 |
| 142 function cache_methods:clear() | |
| 143 self._data = {}; | |
| 144 self._count = 0; | |
| 145 self._head = nil; | |
| 146 self._tail = nil; | |
| 147 end | |
| 148 | |
| 142 local function new(size, on_evict) | 149 local function new(size, on_evict) |
| 143 size = assert(tonumber(size), "cache size must be a number"); | 150 size = assert(tonumber(size), "cache size must be a number"); |
| 144 size = math.floor(size); | 151 size = math.floor(size); |
| 145 assert(size > 0, "cache size must be greater than zero"); | 152 assert(size > 0, "cache size must be greater than zero"); |
| 146 local data = {}; | 153 local data = {}; |
