@@ -146,6 +146,9 @@ func newCacheStore(m *cacheManagerMetrics, dir string, cacheSize, maxItems int64
146
146
}
147
147
logger .Infof ("Disk cache (%s): used ratio - [space %s%%, inode %s%%]" ,
148
148
c .dir , humanize .FtoaWithDigits (float64 ((1 - usage .br )* 100 ), 1 ), humanize .FtoaWithDigits (float64 ((1 - usage .fr )* 100 ), 1 ))
149
+
150
+ c .setlimitByFreeRatio (usage , c .freeRatio )
151
+
149
152
c .createLockFile ()
150
153
go c .checkLockFile ()
151
154
go c .flush ()
@@ -159,6 +162,21 @@ func newCacheStore(m *cacheManagerMetrics, dir string, cacheSize, maxItems int64
159
162
return c
160
163
}
161
164
165
+ func (cache * cacheStore ) setlimitByFreeRatio (usage DiskFreeRatio , freeRatio float32 ) {
166
+ sizeLimit := int64 (float64 (1 - freeRatio ) * float64 (usage .spaceCap ))
167
+ inodeLimit := int64 (float64 (1 - freeRatio ) * float64 (usage .inodeCap ))
168
+ if sizeLimit < cache .capacity {
169
+ limit := cache .capacity
170
+ cache .capacity = sizeLimit
171
+ logger .Infof ("Adjusted cache capacity based on freeratio: from %d to %d bytes" , limit , cache .capacity )
172
+ }
173
+ if inodeLimit < cache .maxItems || cache .maxItems == 0 {
174
+ limit := cache .maxItems
175
+ cache .maxItems = inodeLimit
176
+ logger .Infof ("Adjusted max items based on freeratio: from %d to %d items" , limit , cache .maxItems )
177
+ }
178
+ }
179
+
162
180
func (cache * cacheStore ) lockFilePath () string {
163
181
return filepath .Join (cache .dir , ".lock" )
164
182
}
0 commit comments