-
Hi all, First of all, thanks a lot for the library! Example: if (!meta.Target.Parameters["cache"].Value)
{
return meta.Proceed(); // Don't cache
}
else
{
// Cache logic...
} This gives an error: Cannot implicitly convert type 'object' to 'bool'. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Answered by
gfraiteur
Aug 1, 2022
Replies: 1 comment 2 replies
-
This code (open in online sandbox) works for me: public override dynamic? OverrideMethod()
{
// Builds the caching string.
var cacheKey = GetCachingKeyFormattingString().ToValue();
var cacheParameter = meta.Target.Parameters.SingleOrDefault( p => p.Name == "skipCache" );
if ( cacheParameter != null )
{
if ( (bool) cacheParameter.Value )
{
return meta.Proceed();
}
}
// Cache lookup.
if ( SampleCache.Cache.TryGetValue( cacheKey, out object value ) )
{
// Cache hit.
return value;
}
else
{
// Cache miss. Go and invoke the method.
var result = meta.Proceed();
// Add to cache.
SampleCache.Cache.TryAdd( cacheKey, result );
}
} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
gfraiteur
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code (open in online sandbox) works for me: