* Create key-value caches of limited size * @returns {Function(string, Object)} Returns the Object data after storing it on itself with * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength) * deleting the oldest entry
()
| 329 | */ |
| 330 | |
| 331 | function createCache() { |
| 332 | var keys = []; |
| 333 | |
| 334 | function cache(key, value) { |
| 335 | // Use (key + " ") to avoid collision with native prototype properties (see Issue #157) |
| 336 | // 为了避免缓存太多,导致内存使用过大,所以这里可以设置cache长度。默认是 |
| 337 | // cacheLength: 50, |
| 338 | if (keys.push(key += " ") > Expr.cacheLength) { |
| 339 | // Only keep the most recent entries |
| 340 | // 超过缓存,那就把缓存的第一个删掉 |
| 341 | delete cache[keys.shift()]; |
| 342 | } |
| 343 | return (cache[key] = value); |
| 344 | } |
| 345 | return cache; |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * Mark a function for special use by Sizzle |