Cache management system for Unity3D.
Install into your project by using latest unitypackage.
IUnicache cache = new FileCache();
You can select these cache instances.
- FileCache: File based cache, all cache data is stored into file.
- MemoryCache: Memory based cache, all cache is stored on memory.
You have to setup some components like following.
cache.Handler = new SimpleDownloadHandler();
cache.UrlLocator = new SimpleUrlLocator();
cache.CacheLocator = new SimpleCacheLocator();
Handler:
- It describes how to retrieve original data.
- SimpleDownloadHandler implements GET request by using UnityWebRequest.
- If you customize to use your Handler such as WWW, BestHTTP and so on, implment ICacheHandler.
UrlLocator:
- It describes how to generate url which used in Handler.
- SimpleUrlLocator implments plain conversion CacheKey to Url. (it means key is url).
- If you customize to use your UrlLocator, implement IUrlLocator.
CacheLocator:
- It describes stored data location.
- SimpleCacheLocator generates cache path as using SHA1 digest.
- If you customize to use your CacheLocator, implement ICacheLocator.
cache.Fetch
retrieves data without thinking about the data is cached or not.
cache.Fetch("http:://localhost/image.png")
.ByteToTexture2D()
.Subscribe(texture => rawImage.texture = texture);
That's all!! Simple usage and easy to cache.
If you are interested in cache versioning, check Versioning Example.
- @nastajus for fixing onError handling bug.