Skip to content

Commit c4ef658

Browse files
OmniTroidclaude
andcommitted
Cache assets by server domain to prevent conflicts
Assets from different servers are now cached in separate subdirectories based on the asset URL's host and path (e.g., direct.grave.wine/base/). This prevents cache conflicts when connecting to different servers. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f524041 commit c4ef658

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

src/webcache.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,41 @@ QString WebCache::cacheDir() const
2727
return get_base_path() + "webcache/";
2828
}
2929

30+
QString WebCache::cacheSubdir() const
31+
{
32+
QString assetUrl = ao_app->m_serverdata.get_asset_url();
33+
if (assetUrl.isEmpty())
34+
{
35+
return QString();
36+
}
37+
38+
// Extract host and path from asset URL (e.g., "https://direct.grave.wine/base/" -> "direct.grave.wine/base/")
39+
QUrl url(assetUrl);
40+
QString subdir = url.host() + url.path();
41+
42+
// Ensure it ends with /
43+
if (!subdir.endsWith('/'))
44+
{
45+
subdir += '/';
46+
}
47+
48+
return subdir;
49+
}
50+
3051
QString WebCache::getCachedPath(const QString &relativePath) const
3152
{
3253
if (relativePath.isEmpty())
3354
{
3455
return QString();
3556
}
3657

37-
QString localPath = cacheDir() + relativePath;
58+
QString subdir = cacheSubdir();
59+
if (subdir.isEmpty())
60+
{
61+
return QString();
62+
}
63+
64+
QString localPath = cacheDir() + subdir + relativePath;
3865

3966
if (!file_exists(localPath))
4067
{
@@ -108,11 +135,18 @@ void WebCache::resolveOrDownload(const QString &relativePath, const QStringList
108135
return;
109136
}
110137

138+
// Get cache subdirectory for this server's asset URL
139+
QString subdir = cacheSubdir();
140+
if (subdir.isEmpty())
141+
{
142+
return;
143+
}
144+
111145
// Try each suffix
112146
for (const QString &suffix : suffixes)
113147
{
114148
QString fullPath = relativePath + suffix;
115-
QString localPath = cacheDir() + fullPath;
149+
QString localPath = cacheDir() + subdir + fullPath;
116150

117151
// Skip if already cached and not expired
118152
if (file_exists(localPath) && !isExpired(localPath))

src/webcache.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ private Q_SLOTS:
7070
// Track failed downloads to avoid retrying them repeatedly
7171
QSet<QString> m_failed_downloads;
7272

73+
/**
74+
* @brief Returns the cache subdirectory for the current server's asset URL.
75+
* E.g., "https://direct.grave.wine/base/" -> "direct.grave.wine/base/"
76+
*/
77+
QString cacheSubdir() const;
78+
7379
/**
7480
* @brief Initiates an async download for the given remote URL.
7581
* @param remoteUrl The full URL to download from.

0 commit comments

Comments
 (0)