private static IEnumerator updateWWWrapperWithCacheOnResponse(WWWrapper wwwrapper) { WWW www = wwwrapper.www; yield return(www); if (www != null && www.responseHeaders != null && www.responseHeaders.ContainsKey("WWW-Cache")) { long cacheTimeMs = Convert.ToInt64(www.responseHeaders ["WWW-Cache"]); if (cacheTimeMs > 0L) { // UnityEngine.Debug.Log("Updated to " + cacheTimeMs); wwwrapper.updateCacheTime(cacheTimeMs); } else if (cacheTimeMs == 0L) { // UnityEngine.Debug.Log("Removed cache!"); Cache.Remove(wwwrapper.url); } } }
// cacheTimeMs = 0 means no cache time (expire directly) - default (-1) means to read the response and get specific header with timeout public static WWW Get(string url, long cacheTimeMs = -1) { WWW www; if (cacheTimeMs != 0 && CacheWWW.HasValidCache(url)) { // UnityEngine.Debug.Log("CACHED"); www = Cache[url].www; } else { // UnityEngine.Debug.Log("NOT CACHED"); WWWrapper wwwrapper = new WWWrapper(url, cacheTimeMs); Cache.Add(url, wwwrapper); www = wwwrapper.www; if (cacheTimeMs == -1) { // Read header in response and use as cachetime Singleton <SingletonInstance> .Instance.StartCoroutine(updateWWWrapperWithCacheOnResponse(wwwrapper)); } } return(www); }