question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Currently the Dictionary cache is not thread safe. You can replace the current code with the following to correct

`using System; using System.Collections.Concurrent; using System.Collections.Generic;

namespace DeviceDetectorNET.Cache { public class DictionaryCache : ICache { private static readonly Object LockObj = new Object(); private static ConcurrentDictionary<string,object> _staticCache = new ConcurrentDictionary<string, object>(); public bool Contains(string id) { return _staticCache !=null && _staticCache.Keys.Count > 0 && _staticCache.ContainsKey(id); } public bool Delete(string id) { object obj; _staticCache.TryRemove(id, out obj); return true; }

public object Fetch(string id)
    {
        return Contains(id) ? _staticCache[id] : null;
    }

public bool FlushAll()
    {
        _staticCache = new ConcurrentDictionary<string, object>();
        return true;
    }

public bool Save(string id, object data, int lifeTime = 0)
    {

            if (Contains(id))
            {
                _staticCache[id] = data;
            }
            else
            {
                _staticCache.TryAdd(id, data);
            }
            return true;

    }
}

}`

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
totperocommented, Jun 13, 2019

Hi @hugoqribeiro , The .NetCore repo is fork from this repo, is not maintained from us. Here is one pull request to port this library to core but is some issues if i do this: here

0reactions
totperocommented, Sep 2, 2019

Hi @hugoqribeiro, this library now is also supported .net core if you want to use it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Thread safety - Wikipedia
Thread safety is a computer programming concept applicable to multi-threaded code. Thread-safe code only manipulates shared data structures in a manner that ...
Read more >
What is the meaning of the term "thread-safe"?
As others have pointed out, thread safety means that a piece of code will work without errors if it's used by more than...
Read more >
Thread Safety (Multithreaded Programming Guide)
Thread safety is the avoidance of data races--situations in which data are set to either correct or incorrect values, depending upon the order...
Read more >
What Is Thread-Safety and How to Achieve It?
This means that different threads can access the same resources without exposing erroneous behavior or producing unpredictable results. This ...
Read more >
Thread Safety in Java
Thread safety in java is the process to make our program safe to use in multithreaded environment, there are different ways through which...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found