Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom CacheKeyGenerator not being used in some cases #243

Open
lilmidnit opened this issue Jul 12, 2018 · 2 comments
Open

Custom CacheKeyGenerator not being used in some cases #243

lilmidnit opened this issue Jul 12, 2018 · 2 comments

Comments

@lilmidnit
Copy link

I have created a customer CacheKeyGenerator which inherits from the default and overrides MakeBaseKey. It is working fine running it local no matter how I reference it (outputcache attribute or registering it) but when it is deployed to the server it uses the DefaultCacheKeyGenerator.

I am also using a custom cacheoutputprovider and this does work both locally and on the server.

[CacheOutput(ClientTimeSpan = 1, ServerTimeSpan = 120, CacheKeyGenerator = typeof(BearerControllerCacheKeyGenerator))]
and
I have tried registering it in global.asax
config.CacheOutputConfiguration().RegisterCacheKeyGeneratorProvider(() => new BearerControllerCacheKeyGenerator());
and
config.CacheOutputConfiguration().RegisterDefaultCacheKeyGeneratorProvider(() => new BearerControllerCacheKeyGenerator());
and I also use Ninject so I added it in there as well
kernel.Bind<ICacheKeyGenerator>().To<BearerControllerCacheKeyGenerator>();

I have tried each of the above singly and all combinations together. I am at a loss as you why once deployed it will not use the customer key generator. There are no errors, the cache will work but it will use the default key generator.

Any help would be appreciated.

@lilmidnit
Copy link
Author

I misinterpreted what was happening. It was running my custom key generator but was not running my override method. When moving the changes to the MakeCacheKey method it would then error that DefaultCacheKeyGenerator.MakeCacheKey method was not found - but only when run on the server. Once I removed the base class and implemented all the code locally it ran correctly.

I'm not sure at this point why the server did not have access to the DefaultCacheKeyGenerator properly.

@Iamcerba
Copy link

Iamcerba commented Dec 4, 2018

@lilmidnit, if you are going to use BearerControllerCacheKeyGenerator directly in CacheOutputAttribute it should be registered explicitly in IoC. Only this way default registered cache key generator will be overridden.

Something like this:

Bind<BearerControllerCacheKeyGenerator>().To<BearerControllerCacheKeyGenerator>();

or

Bind<BearerControllerCacheKeyGenerator>().ToSelf();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants