Initial QSfera import
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
package twwidth
|
||||
|
||||
import "github.com/olekukonko/tablewriter/pkg/twcache"
|
||||
|
||||
// widthCache stores memoized results of Width calculations to improve performance.
|
||||
var widthCache *twcache.LRU[cacheKey, int]
|
||||
|
||||
type cacheKey struct {
|
||||
eastAsian bool
|
||||
str string
|
||||
}
|
||||
|
||||
// SetCacheCapacity changes the cache size dynamically
|
||||
// If capacity <= 0, disables caching entirely
|
||||
func SetCacheCapacity(capacity int) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
if capacity <= 0 {
|
||||
widthCache = nil // nil = fully disabled
|
||||
return
|
||||
}
|
||||
|
||||
newCache := twcache.NewLRU[cacheKey, int](capacity)
|
||||
widthCache = newCache
|
||||
}
|
||||
Reference in New Issue
Block a user