AspNetCore.CacheOutput icon indicating copy to clipboard operation
AspNetCore.CacheOutput copied to clipboard

Issue with InvalidateCacheOutput from another controller

Open hflexgrig opened this issue 5 years ago • 3 comments

Having this action filter [InvalidateCacheOutput("Get", typeof(WeatherForecastController))]. On another controller not working because of constructor overloads

 public InvalidateCacheOutputAttribute(string methodName, Type cacheKeyGeneratorType = default(Type))
            : this(methodName, null, cacheKeyGeneratorType)
        {
        }

        public InvalidateCacheOutputAttribute(
            string methodName,
            Type controllerType,
            Type cacheKeyGeneratorType = default(Type)
        )
        {
            this.controller = controllerType != null ? controllerType.FullName : null;
            this.methodName = methodName;
            this.cacheKeyGeneratorType = cacheKeyGeneratorType;
        }

The only way it works is having

[InvalidateCacheOutput("Get", typeof(WeatherForecastController), typeof(DefaultCacheKeyGenerator))]

Can this be improved ? So we don't have to specify cachekey

hflexgrig avatar Sep 05 '21 00:09 hflexgrig

ALso, you could pass null. Any suggestions?

Iamcerba avatar Sep 05 '21 08:09 Iamcerba

@Iamcerba I'd recommend instead of constructor chaining having two different constructors

public InvalidateCacheOutputAttribute(string methodName, Type cacheKeyGeneratorType = default(Type)){}

and

public InvalidateCacheOutputAttribute(Type controllerType, string methodName, Type cacheKeyGeneratorType = default(Type))

What do you think?

hflexgrig avatar Sep 05 '21 08:09 hflexgrig

Agree, will be a part of the 2.0 release as soon as it may be breaking.

Iamcerba avatar Sep 05 '21 09:09 Iamcerba