Skip to content

Conversation

onetocny
Copy link

@onetocny onetocny commented Dec 2, 2020

As described in #263 it is quite limiting to be able to set up cache timeout only in seconds. So that I have added new TimeSpan properties to CacheOutputAttribute to set client, server and shared timeout. Also usage of ShortTime was replaced by new implementation of IModelQuery<DateTime, CacheTime> called PreciseTime that takes TimeSpan as constructor parameters.

ondrej.netocny added 2 commits December 1, 2020 21:46
…s using TimeSpan. Added new properties to CacheOutputAttribute to be able to specify timeouts by TimeSpan and used PreciseTime.
@filipw
Copy link
Owner

filipw commented Dec 2, 2020

Thanks. The main problem is TimeSpan is not a compile time constant so it cannot be used in an attribute declaration.
I would probably rather see an extra property exposing milliseconds.

@onetocny
Copy link
Author

onetocny commented Dec 2, 2020

Sorry I did not realize that. I was trying to come up with something complex that would cover most of scenarios. What do you think about string properties that would be parsed into TimeSpan internally (see https://docs.microsoft.com/en-us/dotnet/api/system.timespan.parseexact?view=net-5.0).

… cannot be passed as attribute property. Added client and server side tests.
@filipw
Copy link
Owner

filipw commented Dec 2, 2020

I would still prefer to just have another set of properties that allow you to set milliseconds as ints.
Otherwise there is no compile time safety anyway, as invalid strings can blow up the timespans.

@onetocny
Copy link
Author

onetocny commented Dec 2, 2020

No problem, you are the boss here :-). There will be enough flexibility even with milliseconds. May I suggest ulong as data type for these new properties?

@filipw
Copy link
Owner

filipw commented Dec 2, 2020

yes that would make sense. I would make it nullable too. This way if you don't set it, the existing properties kick in automatically, and if you set the new milliseconds ones, they'd take precedence over the old ones (btw it's a bit unfortunate that the existing ones are not nullable too).

We probably also need a comment on both the old properties and the new ones explaining this order of precedence.

@onetocny
Copy link
Author

onetocny commented Dec 2, 2020

I think that nullable is not necessary. In my PR both old and new properties points to backing fields that are TimeSpan. If you do not set neither new nor old one property backing field will keep its default value that is zero. Agree that comments and docs should be extended to prevent people from confusion.

@filipw
Copy link
Owner

filipw commented Dec 2, 2020

yes I get that but what if you set both? it should be deterministic

@onetocny
Copy link
Author

onetocny commented Dec 2, 2020

Sorry I probably do not see your point here. How would nullable solve the undeterministic behavior when you set both secs and millis?

@filipw
Copy link
Owner

filipw commented Dec 2, 2020

  • what happens when you set [CacheOutput(ServerTimeSpan = 10, ServerTimeSpanMilliseconds = 5000)]. Is it 5 seconds or 10 seconds? does it behave the same way on all compiler versions?
  • what happens when you set [CacheOutput(ServerTimeSpanMilliseconds = 5000)]. Is it 5 seconds or 0 seconds?
  • what happens when you set [CacheOutput(ServerTimeSpan = 5, ServerTimeSpanMilliseconds = 0)]. Is it 5 seconds or 0 seconds?

if the new one is nullable you at least know that it was set or not set and can define behvioral rules based on that

@onetocny
Copy link
Author

onetocny commented Dec 3, 2020

I see your point that if someone set both secs and millis it is not clear what should have precedence. But nullable does not solve it imho. Event when you make one of the properties nullable. You will still have to face the case that you have described [CacheOutput(ServerTimeSpan = 10, ServerTimeSpanMilliseconds = 5000)]. You will have two values and decide which one you would like to use. It migh be solved by one of following:

  • In docs and comments specify that secs have precendence over millis or vice versa if both are non zero and implement that in code (just compare it to zero).
  • In docs and comments specify that this scenario (both millis and secs are non zero) is not defined.
  • Change current props to double and do not introduce new ones. Double can be multiplied by 1000 and casted to ulong which would server as timeout in millis.
  • Something else?

@onetocny
Copy link
Author

onetocny commented Dec 8, 2020

@filipw Is there anything I could do to move this PR forward?

@filipw
Copy link
Owner

filipw commented Dec 8, 2020

The problem in what you are proposing is that you have no way of knowing if the 0 on milliseconds is intentional (set by user) or default value.

What I would like to see is as follows:

  • milliseconds are nullable
  • if they are null, existing property is used
  • if both are set, milliseconds are used as they are given precedence

This is less ambiguous.

Copy link
Owner

@filipw filipw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@onetocny
Copy link
Author

onetocny commented Dec 8, 2020

Thanks for cooperation. Glad to contribute.

@onetocny
Copy link
Author

onetocny commented Dec 9, 2020

@filipw As you approved this PR would you please merge it and release new version of nuget?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants