Caching solution for WWW for any type of resource including images, movietexture*, audio* and assetbundles.
** Features **
- Versioning
- Supports HTTP Caching like ETAG
- Autoexpiring mechanism
- Customizable Maximum Cache size.
- Ability to delete specific cache by URL
- Auto Cache cleanup (FIFO basis) constrained by Max Cache Size
Supports iOS, Android, Windows, MacOS and Linux
* depends on the target platform and the source format.
To set the maximum allowed Cache Size.
By default (if not called) it is 50 MB.
HybCache.SetMaxCacheSize(20000000); // Setting the max cache size. 20 MB
To enable Expiry mechanism, which will delete the file(s) if they are older than given time.
This is optional if you are using versioning.
HybCache.EnableExpiry();
If Expiry mechanism is enabled then to set the age or timelimit using the following functions.
// as Hours
HybCache.SetExpiryAgeHours(10);
// Or this
HybCache.SetExpiryAgeDays(1);
// Or like this
HybCache.SetExpiryAgeMinutes(1000);
// or even something like this
HybCache.SetExpiryAgeDays(2.5f);
To disable Expiry mechanism. Use this.
If you are not using Versioning then it is MUST to enable Expiry mechanism and use it!
HybCache.DisableExpiry();
To delete the cache via code, use this
HybCache.Clear();
To delete specific cache
HybCache.DeleteCache("specify the url");
HybCache.DeleteCache("http://hybriona.com/services/api/extraservices/images/banner/alienracer.png");
Now, the most important and also the most easiest part -
To use it!
new WWW() can be easily replaced by one line function.
Following are the variations of the usage.
WWW www = HybWWW.LoadUrl(url,version (optional and can be null for defaults) );
WWW www = HybWWW.LoadUrl("http://hybriona.com/website/images/banner_logo.jpg","3.478.2");
yield return www;
if(www.error == null)
{
// Process the resource
}
else
{
Debug.LogError(www.error);
}
// Or this
WWW www = HybWWW.LoadUrl("http://hybriona.com/website/images/banner_logo.jpg",null);
// Or even like this
WWW www = HybWWW.LoadUrl("http://hybriona.com/website/images/banner_logo.jpg");
It is also possible to implement event based WWW Request.
HybWWW.LoadUrl("url","version (optional and can be null for defaults)",delegate);
HybWWW.LoadUrl("http://hybriona.com/website/images/banner_logo.jpg","3.2820",delegate(WWW www) {
if(www.error == null)
{
// Process the resource
}
else
{
Debug.LogError(www.error);
}
});
// Or even like this
void Start()
{
HybWWW.LoadUrl("http://hybriona.com/website/images/banner_logo.jpg","3.2820",HybWWWLoadedEvent);
}
void HybWWWLoadedEvent(WWW www)
{
if(www.error == null)
{
// Process the resource
}
else
{
Debug.LogError(www.error);
}
}
Default HTTP headers caching can also be used now. This doesn't need any manual versioning in the code.
It supports ETAG too. For more info visit
here.
HybWWW.LoadUrlHC("url",delegate);
string url_http_cache = "http://apis.hybriona.com/hybriona/unity/hugetext";
HybWWW.LoadUrlHC(url_http_cache,delegate(WWW www)
{
if(string.IsNullOrEmpty(www.error))
{
Debug.Log(www.text);
}
else
{
Debug.LogError(www.error);
}
});
For any query, feedback or suggestion feel free to shoot a mail at :
Rajkumar Pramanik (alias RJ proz)
rjproz@gmail.com