Aaron I
Aaron I
CC#
Created by Aaron I on 10/26/2023 in #help
✅ Caching with IMemoryCache, is there a difference?
Is there any difference between this:
var entity = ...;
_cache.CreateEntry(entity.id).SetValue(entity).SetSlidingExpiration(TimeSpan.FromMinutes(ExpirationInMinutes));
var entity = ...;
_cache.CreateEntry(entity.id).SetValue(entity).SetSlidingExpiration(TimeSpan.FromMinutes(ExpirationInMinutes));
and the way that presented in the docs ?:
public IActionResult CacheTryGetValueSet()
{
DateTime cacheEntry;

if (!_cache.TryGetValue(CacheKeys.Entry, out cacheEntry))
{
cacheEntry = DateTime.Now;

var cacheEntryOptions = new MemoryCacheEntryOptions()
.SetSlidingExpiration(TimeSpan.FromSeconds(3));

_cache.Set(CacheKeys.Entry, cacheEntry, cacheEntryOptions);
}

return View("Cache", cacheEntry);
}
public IActionResult CacheTryGetValueSet()
{
DateTime cacheEntry;

if (!_cache.TryGetValue(CacheKeys.Entry, out cacheEntry))
{
cacheEntry = DateTime.Now;

var cacheEntryOptions = new MemoryCacheEntryOptions()
.SetSlidingExpiration(TimeSpan.FromSeconds(3));

_cache.Set(CacheKeys.Entry, cacheEntry, cacheEntryOptions);
}

return View("Cache", cacheEntry);
}
2 replies
CC#
Created by Aaron I on 9/27/2023 in #help
❔ Services becoming dependent on each-other, possible solution, opinions?
No description
20 replies
CC#
Created by Aaron I on 9/26/2023 in #help
✅ Reoccurring times with a possibility to a one time rep in C#
Suppose we have an entity which represents irl event, this event can reoccur every week or be one-time event. How should I manage it? currently my code is pretty disgusting I'm getting a boolean value _reoccurring which determines which type it is. Then, depends on the value I either assign the following properties accordingly:
//null when is one-time, can be separated to a designated struct:
DayOfWeek Day { get; set; }
TimeSpan Start {...}
TimeSpan End {...}
//null when reoccurring:
DateTime Start {...}
DateTime End {...}
//null when is one-time, can be separated to a designated struct:
DayOfWeek Day { get; set; }
TimeSpan Start {...}
TimeSpan End {...}
//null when reoccurring:
DateTime Start {...}
DateTime End {...}
It might be stupid and I'm missing something which makes it easier a lot more, but after digging SO for 30min I decided to come here. There is separation between the two because I don't want a bound to a specific date when working on reoccurring time-events. Another idea I thought of is using the same boolean prop (_reoccurring), keep Start and End props and depends on _reoccurring value I will ignore/ include the date that Start and End bound to. However, I don't know if it's a reasonable/proper solution.
53 replies