Skip to content

Commit 2e39c1e

Browse files
abstractmachinesspenap
authored andcommitted
Control on-disk cache size with env var WPE_DISK_CACHE_SIZE
HTTP disk cache is disabled if there's not enough disk space.
1 parent e5cc8f9 commit 2e39c1e

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Source/WebKit/Shared/CacheModel.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
#include "CacheModel.h"
2828

2929
#include <algorithm>
30+
#include <wtf/Assertions.h>
3031
#include <wtf/RAMSize.h>
3132
#include <wtf/Seconds.h>
3233
#include <wtf/StdLibExtras.h>
34+
#include <wtf/text/WTFString.h>
35+
#include <wtf/text/StringToIntegerConversion.h>
3336

3437
namespace WebKit {
3538

@@ -170,6 +173,25 @@ uint64_t calculateURLCacheDiskCapacity(CacheModel cacheModel, uint64_t diskFreeS
170173
ASSERT_NOT_REACHED();
171174
};
172175

176+
auto s = String::fromLatin1(getenv("WPE_DISK_CACHE_SIZE"));
177+
if (!s.isEmpty()) {
178+
String value = s.trim(deprecatedIsSpaceOrNewline).convertToLowercaseWithoutLocale();
179+
size_t units = 1;
180+
if (value.endsWith('k'))
181+
units = KB;
182+
else if (value.endsWith('m'))
183+
units = MB;
184+
if (units != 1)
185+
value = value.substring(0, value.length()-1);
186+
187+
urlCacheDiskCapacity = parseInteger<uint64_t>(value).value_or(0) * units;
188+
if (urlCacheDiskCapacity > diskFreeSize * MB) {
189+
WTFLogAlways("Disabling cache due to lack of disk space (wanted space: %ju, disk free space: %ju [bytes])",
190+
urlCacheDiskCapacity, diskFreeSize * MB);
191+
urlCacheDiskCapacity = 0;
192+
}
193+
}
194+
173195
return urlCacheDiskCapacity;
174196
}
175197

0 commit comments

Comments
 (0)