0

I have this specific scenario:

  1. The user is sending me request which contains a URL to a file in my private repository.
  2. The server side catch this request and Download the file.
  3. The server making some calculation on the downloaded file.
  4. The server sending the results back to client.

I implemented this in the "Naive" way. Which mean, I downloading the file (step 2) for each request. In most cases, the user will send the same file. So, I thought about better approach: keep the downloaded file in short term "cache".

This mean, I will download the item once, and use this for every user request.

Now the question is, how to manage those files?

In "perfect world", I will use the downloaded file for up to 30 minutes. After this time, I won't use it any more. So, optional solutions are:

  1. Making a file system mechanism to handling files for short terms. Negative: Complex solution.
  2. Using temporary directory to do this job (e.g. Path.GetTempFileName()). Negative: What if the system will start to delete those files, in the middle of reading it?

So, it's seems that each solution has bad sides. What do you recommend?

No1Lives4Ever
  • 6,430
  • 19
  • 77
  • 140
  • This looks like a xy problem...you are explaining us your proposed solution instead of the problem that you are trying to solve! – Hackerman Aug 26 '16 at 17:06
  • I trying to avoid downloading same file for each request. Download one time, use it each time. – No1Lives4Ever Aug 26 '16 at 17:12
  • How about you cache the file names and path in memory with the expiry (30 minutes) and attach the CacheEntryRemovedCallback to the items, so you can delete the files that their associated entries are removed from cache. http://stackoverflow.com/questions/7656682/net-4-objectcache-can-we-hook-into-a-cache-expired-event – Sparrow Aug 26 '16 at 17:14

0 Answers0