Skip to content

Conversation

@afshinm
Copy link
Contributor

@afshinm afshinm commented Jun 1, 2023

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

PR Title

Adds missing Cache.Insert overload

PR Description
Caching.Cache.Insert is missing the overload with 3 arguments, see: https://learn.microsoft.com/en-us/dotnet/api/system.web.caching.cache.insert?view=netframework-4.8.1#system-web-caching-cache-insert(system-string-system-object-system-web-caching-cachedependency)

Addresses #347

@afshinm
Copy link
Contributor Author

afshinm commented Jun 1, 2023

@twsouthwick
Copy link
Member

You'll want to run ./update-apis.ps1 in the root of the project


public void Insert(string key, object value, CacheDependency? dependencies)
{
var policy = new CacheItemPolicy
Copy link
Member

Choose a reason for hiding this comment

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

What about the dependency argument? The original implementation is here: https://referencesource.microsoft.com/#System.Web/Cache/cache.cs,d083199dcfb5f0da - feel free to copy the implementation from there to here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right yeah, sorry the signature is not correct. Will fix later today.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is that why the build is failing btw?

Copy link
Member

Choose a reason for hiding this comment

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

possibly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@twsouthwick CacheDependency argument is not currently being consumed in other methods but there is an unused private AddChangeMonitors that was introduced in this commit 66276e5#diff-bfdc712f9e9845bfd447d4eb1cbbafdb48e1d076e57108d882eb3651699290a9R52 -- This is a good potential solution to consume and monitor the cache dependencies.

I'm happy to refactor other methods as well but I wanted to double check with you first.

Copy link
Member

Choose a reason for hiding this comment

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

@CZEMacLeod you did the original implementation here - thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

@twsouthwick I know there was a little bit of code missing from the implementation that I found when I was doing the VirtualPathProvider implementation.
There are changes in my branch https://github.com/CZEMacLeod/systemweb-adapters/tree/czemacleod/vpp-1.1 that I think include this overload and also sort out some other stuff that was not fully implemented.
I've been meaning to complete the branch for VPP and submit a PR, but while I have a good test/sample implementation, I don't have any good explicit tests defined.
It would probably be good if I separated out all the Cache changes from the VPP changes, as they are fixes/enhancements rather than a new feature but I haven't had time to complete this work yet.
Let me see if I can update my branch and pull all the cache specific code out into a PR.
One thing I found was that there were a few things (like HasChanged) that don't behave quite as logically as you would expect on the System.Web Cache implementation compared to the more generic version that was introduced later. I know that I did catch these inconsistencies and match them like for like in the update I did.

Copy link
Contributor

Choose a reason for hiding this comment

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

I created #351 which contains all the changes I had queued for Cache and CacheDependency.
I've added the tests from this PR, and the missing overload for Cache.Insert. The test here for NoSliding/NoAbsolute is technically covered by Cache.Insert(String, Object)
I also have tests when there is an actual dependent object (file or item).

HasChanged = changeMonitors.Any(cm => cm.HasChanged && (cm.GetLastModifiedUtc() > utcStart));
utcLastModified = changeMonitors.Max(cm => cm.GetLastModifiedUtc());
if (HasChanged)
if (changeMonitors.Count > 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check is because changeMonitors count can be 0 (See Init())

Copy link
Member

Choose a reason for hiding this comment

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

wouldn't this not reset HasChanged if it has potentially been set to something? Is this a correctness issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

changeMonitors.Any works and sets HasChanged if changeMonitors count is 0. However, utcLastModified might have an issue if the source list is empty. However, I think that the specific overload of Max for DateTime uses the generic version which uses default(T) in the case of the empty set rather than throwing an error. In this case, it should probably use the test, and set DateTime.MinValue otherwise. I think all the other paths just short circuit (e.g. the Foreach) when there are no items so I don't believe it causes any issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've included this fix in #351

@twsouthwick
Copy link
Member

@afshinm #351 is adding the cache dependency stuff - is there anything missing from that one that isn't here? That one seems a super-set of what you've done here, so we'll probably go with that. Please let me know if there's anything you see as missing there and thanks for the contribution here!

@twsouthwick
Copy link
Member

@afshinm I've merged in #351 - if there's more that's needed for you, please rebase/merge and we can get it in.

@afshinm
Copy link
Contributor Author

afshinm commented Jun 6, 2023

@twsouthwick sounds good. thanks.

@afshinm afshinm closed this Jun 6, 2023
@afshinm afshinm deleted the amehrabani/caching-insert-3 branch June 6, 2023 06:53
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.

3 participants