Thanks for your reply.
It does not make any sense to generate a cache instance during runtime for individual nodes based on their IDs. If you have a system with a million nodes you'd (eventually) end up with a million cache instances.
We will not use this cache for all nodes. It will be used only for certain file types which is very less in number.
As far as you have described it, your use case would work with a single pre-configured instance. If you have a custom action you should already have some custom Java code (or are you talking about a script action here?) which is configured before starting the server (via an extension / Spring config), and you'd simply add a cache to that implementation, putting in cache data keyed by the NodeRef (you should never rely on node ID in custom code).
Whatever you want to cache, please be aware that you will have to deal with cache data invalidation yourself when changes are made to properties / content that you are caching...
The reason we want to put it based on node Id is, we stored metadata of certain files in another system. We just want to get the metadata from the other system only one time (At very first time any of the user access the custom Action on particular node).
The next time if some other user accesses the same action in same node, we dont want to make another call to get the metadata again.
As you said we if pre configure the cache with some generic name and internally keyed with nodeRef, when we invalidate the cache it will remove all the cached data (Includes all nodeRef and cachedata(metadata) key value pairs- Pls correct me if I am wrong).
We want to specifically invalidate custom cache related to particular nodeRef alone .
So I am seeking for some option to create cache object in runtime and invalidation period also need to specified at the time of creating object.