Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, it just so happens that I've done something almost exactly the same, except that it wasn't actually messages...</p> <p>Here's how I'd handle it.</p> <p>Your service itself talks to a central object (or objects), which can dispatch message requests based on the sender.</p> <p>The object relating to each sender maintains an internal lock while updating anything. When it gets a new request for a modification, it then can read from disk (if necessary), update the data, and write to disk (if necessary).</p> <p>Because different updates will be happening on different threads, the internal lock will be serialized. Just be sure to release the lock if you call any 'external' objects to avoid deadlock scenarios.</p> <p>If I/O becomes a bottleneck, you can look at different strategies involving putting messages in one file, separate files, not immediately writing them to disk, etc. In fact, I'd think about storing the messages for each user in a separate folder for exactly that reason.</p> <p>The biggest point is, that each service instance acts as, essentially, an adapter to the central class, and that only <em>one</em> instance of <em>one</em> class will ever be responsible for reading/writing messages for a given recipient. Other classes may <em>request</em> a read/write, but they do not actually perform it (or even know how it's performed). This also means that their code is going to look like 'AddMessage(message)', not 'SaveMessages(GetMessages.Add(message))'.</p> <p>That said, using a database is a very good suggestion, and will likely save you a lot of headaches.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload