Should I use SetSkipMemoryCacheWrite or SkipMemoryCacheWrite? #506
-
Should I use the property or the method? I can only find documentation for the property but not the method. Are they the same? ![]() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @oasaleh
Yes they do the same thing. Why do they both exist? For example when you do this: var foo = cache.GetOrSet<Foo>(
"foo",
_ => GetFooFromDb(),
options => options.SetSkipMemoryCacheWrite().SetFailSafe(true, TimeSpan.FromSeconds(10))
); without the fluent api methods you need to do this: var foo = cache.GetOrSet<Foo>(
"foo",
_ => GetFooFromDb(),
options => {
options.SkipMemoryCacheWrite = true;
options.IsFailSafeEnabled = true;
options.FailSafeMaxDuration = TimeSpan.FromSeconds(10);
return options;
}
); which is more verbose and distracting. Similar methods exist for all the other options, like Hope this helps. |
Beta Was this translation helpful? Give feedback.
Hi @oasaleh
Yes they do the same thing. Why do they both exist?
Because the property is the actual thing that is used, whereas the method sets the property + returns the entry options themselves, for chaining purposes so you can compose multiple modifications together without having to create an explicit block of code, in a fluent api way.
For example when you do this:
without the fluent api methods you need…