@xinferai/utils-lib
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -250,3 +250,3 @@ /** | ||
/** | ||
* getUUID - Get a UUID from the cache or generate a new one | ||
* getUUID - Get a UUID | ||
* | ||
@@ -253,0 +253,0 @@ * @returns {string} - A UUID |
@@ -963,47 +963,5 @@ "use strict"; | ||
// src/get-uuid.ts | ||
var UUIDCache = class { | ||
/** | ||
* @param {number} cacheSize - The maximum number of UUIDs to cache | ||
* @param {number} lowWaterMark - The minimum number of UUIDs to keep in the cache | ||
*/ | ||
constructor(cacheSize = 666, lowWaterMark = Math.floor(cacheSize * 0.2)) { | ||
this.cacheSize = cacheSize; | ||
this.lowWaterMark = lowWaterMark; | ||
this.cache = []; | ||
this.isGenerating = false; | ||
this.fillCache(); | ||
} | ||
getUUID() { | ||
if (this.cache.length <= this.lowWaterMark) { | ||
this.fillCache(); | ||
} | ||
return this.cache.pop() || v4_default(); | ||
} | ||
// For testing/monitoring | ||
getCacheSize() { | ||
return this.cache.length; | ||
} | ||
fillCache() { | ||
if (this.isGenerating) return; | ||
this.isGenerating = true; | ||
const generateBatch = () => { | ||
const batchSize = 33; | ||
let generated = 0; | ||
while (generated < batchSize && this.cache.length < this.cacheSize) { | ||
this.cache.push(v4_default()); | ||
generated++; | ||
} | ||
if (this.cache.length < this.cacheSize) { | ||
setTimeout(generateBatch, 0); | ||
} else { | ||
this.isGenerating = false; | ||
} | ||
}; | ||
setTimeout(generateBatch, 0); | ||
} | ||
}; | ||
var uuidCache = new UUIDCache(); | ||
// src/get-uuid-browser.ts | ||
var getUUID = () => { | ||
return uuidCache.getUUID(); | ||
return v4_default(); | ||
}; | ||
@@ -1010,0 +968,0 @@ |
@@ -994,3 +994,3 @@ "use strict"; | ||
// src/get-uuid.ts | ||
// src/get-uuid-node.ts | ||
var UUIDCache = class { | ||
@@ -997,0 +997,0 @@ /** |
{ | ||
"name": "@xinferai/utils-lib", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"exports": { | ||
@@ -5,0 +5,0 @@ ".": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
483549
4566