Skip to content

Trying to understand some code parts #20

@zandhaai

Description

@zandhaai

Thank you for this project!

I am stripping some code because I only need some parts, but now I do not understand some things. Given the following part:

Interlocked.Increment(ref Cache.counter);
SimpleObject simpleObject = new SimpleObject {Key = key, Value = value, FileLocation = filelocation};

sendQueue.Add(simpleObject);
var data = sendQueue.Take(); //this blocks if there are no items in the queue.

//Add to cache
Cache.CacheDictionary[filelocation + key] = simpleObject;
ThreadPool.QueueUserWorkItem(state =>
{
Storage.WriteToStorage(data.Key, Compress.CompressGZip(ConvertHelper.ObjectToByteArray(value)), data.FileLocation);
});

My questions:

  1. Why did you implement a sendQueue? The key after a Take() is used in the WriteToStorage. Why can't the key not be used directly?
  2. The above method adds the object to the cache but it is later deleted inside WriteToStorage. Is this wrong or did I miss an important part of code?
  3. Should the statement 'Interlocked.Decrement(ref Cache.counter);' not be after the thread.sleep inside WriteToStorage?

Best regards,

Evert

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions