Debian Codegraph @

vendor/static/jquery/src/selector/createCache.js

raw
1 import { jQuery } from "../core.js";
2
3 /**
4 * Create key-value caches of limited size
5 * @returns {function(string, object)} Returns the Object data after storing it on itself with
6 * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
7 * deleting the oldest entry
8 */
9 export function createCache() {
10 var keys = [];
11
12 function cache( key, value ) {
13
14 // Use (key + " ") to avoid collision with native prototype properties
15 // (see https://github.com/jquery/sizzle/issues/157)
16 if ( keys.push( key + " " ) > jQuery.expr.cacheLength ) {
17
18 // Only keep the most recent entries
19 delete cache[ keys.shift() ];
20 }
21 return ( cache[ key + " " ] = value );
22 }
23 return cache;
24 }