Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 80c405e

Browse files
committed
Cache blob caches
SQLitePersistentBlobCache need to be cached, `ImageCache` creates a new one every time it needs to load an image from the cache, and they persist across the lifetime of the application, resulting in a million tasks just hanging there waiting for work, eventually exhausting system resources.
1 parent be5bb2b commit 80c405e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/GitHub.App/Factories/SqlitePersistentBlobCacheFactory.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Akavache.Sqlite3;
33
using NLog;
44
using System;
5+
using System.Collections.Generic;
56
using System.ComponentModel.Composition;
67

78
namespace GitHub.Factories
@@ -11,14 +12,19 @@ namespace GitHub.Factories
1112
public class SqlitePersistentBlobCacheFactory : IBlobCacheFactory
1213
{
1314
static readonly Logger log = LogManager.GetCurrentClassLogger();
15+
Dictionary<string, IBlobCache> cache = new Dictionary<string, IBlobCache>();
1416

1517
public IBlobCache CreateBlobCache(string path)
1618
{
1719
Guard.ArgumentNotEmptyString(path, nameof(path));
20+
if (cache.ContainsKey(path))
21+
return cache[path];
1822

1923
try
2024
{
21-
return new SQLitePersistentBlobCache(path);
25+
var c = new SQLitePersistentBlobCache(path);
26+
cache.Add(path, c);
27+
return c;
2228
}
2329
catch(Exception ex)
2430
{

0 commit comments

Comments
 (0)