Razorlight: Add ability to use Distributed Cache

Created on 18 Jun 2018  路  4Comments  路  Source: toddams/RazorLight

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

enhancement feature-proposal

Most helpful comment

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 :)

All 4 comments

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

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?

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.

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 :)

Was this page helpful?
0 / 5 - 0 ratings