RazorLight icon indicating copy to clipboard operation
RazorLight copied to clipboard

Add ability to use Distributed Cache

Open tresoldigiorgio opened this issue 7 years ago • 7 comments

I've implemented an ICachingProvider with an IDistributed cache implemented with Redis but I'm not able to succeffully serialize a TemplateCacheItem because is not serializable. I've tried Binary serializer, JSON, Protopuf and MessagePack but no one works. Only inMemory cache work.

I need a serializable object. :-D

tresoldigiorgio avatar Jun 18 '18 12:06 tresoldigiorgio

Your template is built by Roslyn and put into in-memory assembly. Because of that, sharing between multiple instances is not possible at the moment. Possible solution is to add ability to compile templates into real DLLs

toddams avatar Jun 18 '18 12:06 toddams

Can you describe your use-case? You have multiple application servers and you'd like to cache templates to Redis, so they can be shared between all of those instances?

toddams avatar Jun 18 '18 12:06 toddams

It's exactly my case. I have many instance of my application in a docker stack and i would to cache template only one time in redis.

tresoldigiorgio avatar Jun 18 '18 12:06 tresoldigiorgio

In general, having all your servers to compile and cache templates is not bad at all.

If you are storing your templates in files, when file with your template changes - all templates will be invalidated from cache from all your servers, so you don't have to bother about this aspect.

You can also warm-up your containers by compiling all the templates before start. Or use Precompiled templates, feature I haven't done yet :P

But having an ability to use Redis for templates cache sound very nice for me, and it would definitely be interesting to develop :)

toddams avatar Jun 18 '18 13:06 toddams

In general, having all your servers to compile and cache templates is not bad at all.

If you are storing your templates in files, when file with your template changes - all templates will be invalidated from cache from all your servers, so you don't have to bother about this aspect.

You can also warm-up your containers by compiling all the templates before start. Or use Precompiled templates, feature I haven't done yet :P

But having an ability to use Redis for templates cache sound very nice for me, and it would definitely be interesting to develop :)

Probably forgotten but have this been picked up ?

sanket-mistry-jm avatar Mar 24 '22 21:03 sanket-mistry-jm

Please see the comment

Your template is built by Roslyn and put into in-memory assembly. Because of that, sharing between multiple instances is not possible at the moment

Not possible to deliver "mobile code" via distributed cache. It's a fundamental limitation.

Cache the end results, not the templates.

jzabroski avatar Mar 25 '22 01:03 jzabroski

Please see the comment

Your template is built by Roslyn and put into in-memory assembly. Because of that, sharing between multiple instances is not possible at the moment

Not possible to deliver "mobile code" via distributed cache. It's a fundamental limitation.

Cache the end results, not the templates.

I see the limitation But I do not believe in caching end results since that defeats the purpose of using templates. end results will change based on data you provide so it should not be cache unless I am missing something.

sanket-mistry-jm avatar Mar 25 '22 15:03 sanket-mistry-jm