I have a table that stores songs and plays counter.
Here’s the code:
//Increse plays counter
string ip = Request.UserHostAddress;
if (!string.IsNullOrEmpty(ip))
{
if (Cache["plays:" + trackID + ":" + ip] == null)
{
tracks.IncreasePlaysCounter(trackID);
Cache["plays:" + trackID + ":" + ip] = true;
}
}
I wonder what would be a better practice, store many cache items(like this) or store one item like a ArrayList that would contain the users who already heard that song. Is there any difference?
Neither. If your system is in any way successful it will have far too many individual entries being written for this to be able to scale to cope, especially when you add the locking code to deal with the number of simultaneous writes and reads this will have to cope with.
Store this information in a database. Or don’t store it at all, but obtain it by parsing the webserver logs (if the trackID is a query parameter, this information will already be in those logs without any work from you).