1

My api depends on some programs that are expensive to start up for each call. I am trying to inject a cache that contains the cached objects wrapping the programs so they can be reused without killing executables between calls to my api.

Before trying to use a cache each call would start up their own instance of a program and run, which is important as it is wrapped COBOL programs with static variables.

My problem is that I'm not sure how I use the cache such that the cached objects are exclusive while used by a call. I want another program to be started up if another call has already hit the cache with the same key and is still using that value. Would be great if I can somehow build up a pool as needed for each program, some a used a lot, some rarely.

1
  • 4
    This is much more complex than a cache - this sounds like a pool of out-of-process objects; I would start thinking of this as a pool rather than a cache, i.e. "try take from pool" needs to be atomic; that could be as simple as ConcurrentQueue<T> or anything if you synchronize it. Likewise, you need to think what happens if you try to return things and the pool is over-size, etc. A pool lease lifetime might be representable via IDisposable (for using), or it might not! It depends on the failure modes and concurrency - i.e. can it exit/fault with an in-flight operation still running Commented Mar 3 at 16:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.