jamesmontemagno / monkey-cache

Easily cache any data structure for a specific amount of time in any .NET application.
MIT License
670 stars 106 forks source link

Sharing violation on path exception #116

Open vynxc opened 1 year ago

vynxc commented 1 year ago

While Making 2 of the same request to the same url i the System.IO.IOException: 'Sharing violation on path /data/user/0/com.companyname.chaycesanime/cache/com.companyname.chaycesanime/MonkeyCache/Barrel.db' exception.

public static async Task<T> GetAsync<T>(string url, int days = 1, bool forceRefresh = false)
        {
            var json = string.Empty;

            if (Connectivity.NetworkAccess != NetworkAccess.Internet)
                json = Barrel.Current.Get<string>(url);

            if (!forceRefresh && !Barrel.Current.IsExpired(url))
                json = Barrel.Current.Get<string>(url);

            try
            {
                if (string.IsNullOrWhiteSpace(json))
                {
                    json = await client.GetStringAsync(url);
                    Barrel.Current.Add(url, json, TimeSpan.FromDays(days));
                }
                return JsonConvert.DeserializeObject<T>(json);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Unable to get information from server {ex}");
                //probably re-throw here :)
            }

            return default(T);
        }
vynxc commented 1 year ago

sadly i cannot use this plugin without thread support. hope it gets fixed soon. ive tried with file store and light db.