Skip to content

Commit 8f9ebd0

Browse files
authored
Merge pull request #21 from IvanMurzak/20-usediskcache-and-usememorycache-dedicated-control-of-each-loading-task
`useDiskCache and `useMemoryCache` dedicated control of each loading task
2 parents e2942f2 + 33c7f62 commit 8f9ebd0

File tree

15 files changed

+240
-91
lines changed

15 files changed

+240
-91
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,8 @@ crashlytics-build.properties
7373

7474
# ODIN plugin
7575
/Assets/Plugins/Sirenix**
76+
77+
# Other
78+
UserSettings/Layouts/default-2021.dwlt
79+
UserSettings/Layouts/default-2022.dwlt
80+
UserSettings/Layouts/default-6000.dwlt

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"visualstudiotoolsforunity.vstuc"
4+
]
5+
}

.vscode/launch.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Attach to Unity",
6+
"type": "vstuc",
7+
"request": "attach"
8+
}
9+
]
10+
}

.vscode/settings.json

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
{
2-
"files.exclude":
3-
{
4-
"**/.DS_Store":true,
5-
"**/.git":true,
6-
"**/.gitmodules":true,
7-
"**/*.booproj":true,
8-
"**/*.pidb":true,
9-
"**/*.suo":true,
10-
"**/*.user":true,
11-
"**/*.userprefs":true,
12-
"**/*.unityproj":true,
13-
"**/*.dll":true,
14-
"**/*.exe":true,
15-
"**/*.pdf":true,
16-
"**/*.mid":true,
17-
"**/*.midi":true,
18-
"**/*.wav":true,
19-
"**/*.gif":true,
20-
"**/*.ico":true,
21-
"**/*.jpg":true,
22-
"**/*.jpeg":true,
23-
"**/*.png":true,
24-
"**/*.psd":true,
25-
"**/*.tga":true,
26-
"**/*.tif":true,
27-
"**/*.tiff":true,
28-
"**/*.3ds":true,
29-
"**/*.3DS":true,
30-
"**/*.fbx":true,
31-
"**/*.FBX":true,
32-
"**/*.lxo":true,
33-
"**/*.LXO":true,
34-
"**/*.ma":true,
35-
"**/*.MA":true,
36-
"**/*.obj":true,
37-
"**/*.OBJ":true,
38-
"**/*.asset":true,
39-
"**/*.cubemap":true,
40-
"**/*.flare":true,
41-
"**/*.mat":true,
42-
"**/*.meta":true,
43-
"**/*.prefab":true,
44-
"**/*.unity":true,
45-
"build/":true,
46-
"Build/":true,
47-
"Library/":true,
48-
"library/":true,
49-
"obj/":true,
50-
"Obj/":true,
51-
"ProjectSettings/":true,
52-
"temp/":true,
53-
"Temp/":true
2+
"files.exclude": {
3+
"**/.DS_Store": true,
4+
"**/.git": true,
5+
"**/.gitmodules": true,
6+
"**/*.booproj": true,
7+
"**/*.pidb": true,
8+
"**/*.suo": true,
9+
"**/*.user": true,
10+
"**/*.userprefs": true,
11+
"**/*.unityproj": true,
12+
"**/*.dll": true,
13+
"**/*.exe": true,
14+
"**/*.pdf": true,
15+
"**/*.mid": true,
16+
"**/*.midi": true,
17+
"**/*.wav": true,
18+
"**/*.gif": true,
19+
"**/*.ico": true,
20+
"**/*.jpg": true,
21+
"**/*.jpeg": true,
22+
"**/*.png": true,
23+
"**/*.psd": true,
24+
"**/*.tga": true,
25+
"**/*.tif": true,
26+
"**/*.tiff": true,
27+
"**/*.3ds": true,
28+
"**/*.3DS": true,
29+
"**/*.fbx": true,
30+
"**/*.FBX": true,
31+
"**/*.lxo": true,
32+
"**/*.LXO": true,
33+
"**/*.ma": true,
34+
"**/*.MA": true,
35+
"**/*.obj": true,
36+
"**/*.OBJ": true,
37+
"**/*.asset": true,
38+
"**/*.cubemap": true,
39+
"**/*.flare": true,
40+
"**/*.mat": true,
41+
"**/*.meta": true,
42+
"**/*.prefab": true,
43+
"**/*.unity": true,
44+
"build/": true,
45+
"Build/": true,
46+
"Library/": true,
47+
"library/": true,
48+
"obj/": true,
49+
"Obj/": true,
50+
"ProjectSettings/": true,
51+
"temp/": true,
52+
"Temp/": true
5453
},
5554
"dotnet.preferCSharpExtension": true,
5655
"cSpell.words": [
5756
"ARGB"
58-
]
57+
],
58+
"dotnet.defaultSolution": "Unity-ImageLoader.sln"
5959
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
3+
namespace Extensions.Unity.ImageLoader
4+
{
5+
public partial class Future<T> : IDisposable
6+
{
7+
/// <summary>
8+
/// Set disk cache usage for this Future instance
9+
/// </summary>
10+
/// <param name="value">new value</param>
11+
/// <returns>Returns the Future instance</returns>
12+
public Future<T> SetUseDiskCache(bool value = true)
13+
{
14+
UseDiskCache = value;
15+
return this;
16+
}
17+
18+
/// <summary>
19+
/// Set memory cache usage for this Future instance
20+
/// </summary>
21+
/// <param name="value">new value</param>
22+
/// <returns>Returns the Future instance</returns>
23+
public Future<T> SetUseMemoryCache(bool value = true)
24+
{
25+
UseMemoryCache = value;
26+
return this;
27+
}
28+
}
29+
}

Assets/_PackageRoot/Runtime/Future/Future.API.Set.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/_PackageRoot/Runtime/Future/Future.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public partial class Future<T> : IFuture, IDisposable
3232

3333
private readonly CancellationTokenSource cts;
3434
private readonly bool muteLogs;
35+
public bool UseDiskCache { get; private set; }
36+
public bool UseMemoryCache { get; private set; }
3537
private bool cleared = false;
3638
private T value = default;
3739
private Exception exception = default;
@@ -56,10 +58,12 @@ internal Future(string url, CancellationToken cancellationToken, bool muteLogs =
5658
Url = url;
5759
cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
5860
this.muteLogs = muteLogs;
61+
UseDiskCache = ImageLoader.settings.useDiskCache;
62+
UseMemoryCache = ImageLoader.settings.useMemoryCache;
5963
cancellationToken.Register(Cancel);
6064
}
6165
~Future() => Dispose();
62-
66+
6367
internal Future<T> PassEvents(Future<T> to, bool passCancelled = true)
6468
{
6569
LoadedFromMemoryCache((v) => to.Loaded(v, FutureLoadedFrom.MemoryCache));

Assets/_PackageRoot/Runtime/ImageLoader.LoadSprite.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static async void InternalLoadSprite(Future<Sprite> future, Vector2 pivot, Textu
6565
{
6666
Debug.Log(future.IsCancelled
6767
? $"[ImageLoader] Cancelled {future.Url}"
68-
: future.Status == FutureStatus.FailedToLoad
68+
: future.Status == FutureStatus.FailedToLoad
6969
? $"[ImageLoader] Failed to load {future.Url}"
7070
: $"[ImageLoader] Complete waiting for another task to load {future.Url}");
7171
}
@@ -77,7 +77,7 @@ static async void InternalLoadSprite(Future<Sprite> future, Vector2 pivot, Textu
7777

7878
AddLoading(future); // LOADING ADDED
7979

80-
if (settings.useDiskCache && DiskCacheContains(future.Url))
80+
if (future.UseDiskCache && DiskCacheContains(future.Url))
8181
{
8282
future.Loading(FutureLoadingFrom.DiskCache);
8383
try
@@ -95,7 +95,7 @@ static async void InternalLoadSprite(Future<Sprite> future, Vector2 pivot, Textu
9595
if (texture.LoadImage(cachedImage))
9696
{
9797
var sprite = ToSprite(texture, pivot);
98-
if (sprite != null)
98+
if (sprite != null && future.UseMemoryCache)
9999
SaveToMemoryCache(future.Url, sprite, replace: true);
100100

101101
RemoveLoading(future); // LOADING REMOVED
@@ -170,7 +170,7 @@ static async void InternalLoadSprite(Future<Sprite> future, Vector2 pivot, Textu
170170
future.Cancel();
171171
return;
172172
}
173-
173+
174174
#if UNITY_2020_1_OR_NEWER
175175
var isError = request == null || request.result != UnityWebRequest.Result.Success;
176176
#else
@@ -195,7 +195,8 @@ static async void InternalLoadSprite(Future<Sprite> future, Vector2 pivot, Textu
195195
return;
196196
}
197197
var sprite = ToSprite(((DownloadHandlerTexture)request.downloadHandler).texture);
198-
SaveToMemoryCache(future.Url, sprite, replace: true);
198+
if (future.UseMemoryCache)
199+
SaveToMemoryCache(future.Url, sprite, replace: true);
199200
RemoveLoading(future); // LOADING REMOVED
200201
future.Loaded(sprite, FutureLoadedFrom.Source);
201202
}

Assets/_PackageRoot/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
"name": "Ivan Murzak",
66
"url": "https://github.com/IvanMurzak"
77
},
8-
"version": "5.3.3",
8+
"version": "5.4.0",
99
"unity": "2019.2",
1010
"description": "Asynchronous image loading from remote or local destination. It has two layers of configurable Memory and Disk cache systems.",
1111
"dependencies": {
12-
"com.cysharp.unitask": "2.5.4"
12+
"com.cysharp.unitask": "2.5.10"
1313
},
1414
"scopedRegistries": [
1515
{

Packages/manifest.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
{
22
"dependencies": {
3-
"com.cysharp.unitask": "2.5.4",
4-
"com.unity.ide.rider": "3.0.28",
3+
"com.cysharp.unitask": "2.5.10",
54
"com.unity.ide.visualstudio": "2.0.22",
65
"com.unity.ide.vscode": "1.2.5",
7-
"com.unity.test-framework": "1.1.33",
8-
"com.unity.ugui": "1.0.0",
6+
"com.unity.test-framework": "1.4.6",
7+
"com.unity.ugui": "2.0.0",
98
"com.unity.modules.imageconversion": "1.0.0",
109
"com.unity.modules.imgui": "1.0.0",
1110
"com.unity.modules.jsonserialize": "1.0.0",
1211
"com.unity.modules.ui": "1.0.0",
13-
"com.unity.modules.unityanalytics": "1.0.0",
1412
"com.unity.modules.unitywebrequest": "1.0.0",
1513
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
1614
"com.unity.modules.unitywebrequestaudio": "1.0.0",

0 commit comments

Comments
 (0)