Cache is not triggered
Eomm opened this issue · comments
Reading the old code:
https://github.com/fastify/fastify-accepts-serializer/tree/v3.0.1
the cache behaviour can works if the users doesn't customize the serializer
in the route options.
So the cache can be enabled and used from the globalSerializerManager
when reply.serializer
is empty
--
If I am not wrong, the cache in this plugin will never be fired.
The main reason is that SerializerManager.expand
always initialize a new instance and for the preHandler
hook which call the SerializerManager.expand
will lead to always having new cache for each route.
As a result, calling same route multiple times or nesting will not trigger the cache.
Originally posted by @climba03003 in #18 (comment)
The globalSerializerManager
only triggered findSerializer
once when fastify
initial. It is the only function that will trigger the cache. So, even if you do not specify reply.serializer
. The cache can not trigger either.
I have tried to fix this issue before when I first scan the code by inheriting the cache. But no luck.
Another thing is that caches should be in route level, if we share them with global cache. It will mess up all the thing when we specify two different route level serializer with same type.