How to detect if lock is held on named cache item?

Is it possible to detect if the thread has acquired a lock for a particular item in the named cache?
I have an instance where a method is being called from two different streams, and if the lock is being held by the code path, I do not want to release it in the method.
If it is it not held by the calling method, I want to lock it and then release it in the called method.


It's not possible to get this information from the API--you'd need to pass the knowledge of the lock status into the method yourself (or, better yet, let the caller release the lock once the called method returns).
Transferring around the ownership of locks between different methods can make your codebase difficult to maintain since won't be immediately obvious upon reading the code how the lock should be managed (especially when you come back to look at your code a year from now!). I'd recommend restructuring the code to make it immediately obvious what code is responsible for the lifetime of the lock.