To do so we need some kind of the list where we can store key or file ID and associated object that we’ll lock around. The FileCache class uses a local disk to read and write output file copies, so we need to make reads and writes to disk thread-safe. The FileCache is not thread-safe, so our task is to make it thread-safe. The GroupDocs.Viewer enables users to use caching to improve the performance of the application when the same document is processed multiple times ( read more about caching here.) The FileCache is a simple implementation of ICache interface that uses a local disk to store the cache files is available from the namespace. The web-application uses GroupDocs.Viewer on the server-side and we want to make sure that multiple-threads can safely read from and write to the cache, in other words, make cache thread-safe. We have a web-application where multiple users can simultaneously view the same file. The most common way to achieve thread-safety is by locking the resource for the exclusive use by a single thread at any given point of the time. Achieving thread safety is a complex task and so general-purpose classes are usually not thread-safe. We can say that a method is thread-safe when multiple threads can call it without breaking the functionality of this method. This tutorial will explain how to make cache thread-safe by using C# lock and ConcurrentDictionary class.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |