kontent-ai / delivery-sdk-net

Kontent.ai Delivery .NET SDK
https://www.nuget.org/packages/Kontent.Ai.Delivery
MIT License
32 stars 42 forks source link

Allow for fixed expiration on memory cache #252

Closed pablojmp closed 3 years ago

pablojmp commented 3 years ago

Motivation

When using the DeliveryClientCache, one can only set a sliding expiration via DeliveryCacheOptions.DefaultExpiration. If no webhooks are set up for the app and the cache is accessed frequently, there's no way to evict older content.

Proposed solution

Add a parameter to select what type of expiration DefaultExpiration has (i.e. DefaultExpirationType = Absolute | Sliding) and set the expiration accordingly in here

tomasjurasek commented 3 years ago

Hi, thanks for the feedback. You right, there is missing support for the expiration type for the memory cache.

In a few days, I will implement this expiration type enum :)

pablojmp commented 3 years ago

@tomasjurasek thanks a lot for the quick response! is it too much to ask for an ETA on the release of the nuget version that'll contain the patch?

tomasjurasek commented 3 years ago

@pablojmp I do PRV now. It can be probably released tomorrow.

petrsvihlik commented 3 years ago

baking the build at https://github.com/Kentico/kontent-delivery-sdk-net/releases/tag/14.2.0

petrsvihlik commented 3 years ago

@pablojmp here you go: https://www.nuget.org/packages/Kentico.Kontent.Delivery/14.2.0

please let us know if it works fine for you ;)

pablojmp commented 3 years ago

will test right away! thanks guys, that was ultra fast!

pablojmp commented 3 years ago

i was testing this configuration

services.AddDeliveryClientCache(new DeliveryCacheOptions
  {
      StaleContentExpiration = TimeSpan.FromSeconds(2),
      DefaultExpirationType = CacheExpirationType.Absolute,
      DefaultExpiration = TimeSpan.FromSeconds(10),
      CacheType = CacheTypeEnum.Memory
  });

while using wireshark to sniff the traffic. if i keep refreshing a page that fetches content, i don't see more requests to kentico, event after the 10 seconds windows. if i stop refreshing the page and wait 10 seconds before refreshing, the sdk makes the request again. it's behaving as a sliding expiration. am i missing something in the configuration?

pablojmp commented 3 years ago

Maybe this method here

void Configure(DeliveryCacheOptions o)
{
    o.DefaultExpiration = options.DefaultExpiration;
    o.StaleContentExpiration = options.StaleContentExpiration;
    o.CacheType = options.CacheType;
    o.Name = name;
}

it's missing the new property assignment

pablojmp commented 3 years ago

@petrsvihlik @tomasjurasek can you reopen this one?

tomasjurasek commented 3 years ago

@pablojmp sorry, I missed this configuration. Fixed in the 14.2.1

pablojmp commented 3 years ago

@tomasjurasek don't worry, i'm the one who feels sorry for throwing more work at you 😄 thanks again!

pablojmp commented 3 years ago

confirmed: it's working as intended, thanks!