@@ -12,6 +12,7 @@ open Types
1212type CacheData = {
1313 ///hash of the projects assets.json. This is used to see if the project has changed which would invalidate our hash.
1414 assetsHash : string
15+ fsprojHash : string
1516 Project: ResolvedProject
1617 ///Used to allow deleting of old cache data if we make significant changes
1718 version: string
@@ -55,7 +56,13 @@ let extraEncoders=
5556 |> Extra.withCustom
5657 ( fun ( x : Range ) -> Encode.string <| System.Text.Json.JsonSerializer.Serialize( x))
5758 ( fun path value -> Ok ( System.Text.Json.JsonSerializer.Deserialize< Range>( value.ToString()) ))
59+ ///Uses various methods to decide if the cache is still valid or if it needs to be discarded and replaced.
60+ let isCacheValid ( fsprojPath : string ) ( cachePath : string ) ( cacheData : CacheData )=
5861
62+ let assetsPath = Path.Combine( Path.GetDirectoryName( cachePath), " project.assets.json" )
63+ let assetHash = getHash assetsPath
64+ let fsprojHash = getHash fsprojPath
65+ cacheData.assetsHash= assetHash && cacheData.fsprojHash= fsprojHash && cacheData.version= currentVersion
5966///** Attempts to get cached project data.**
6067///
6168///O returns the data if the project.assets.json files hash has not changed. A change would indicate that the cached data may no longer be valid.
@@ -66,11 +73,8 @@ let tryGetCached (fsproj:FileInfo)=
6673
6774 try
6875 let cacheData = match ( Decode.Auto.fromString( cacheJson, extra= extraEncoders)) with | Ok a-> a| Error e-> failwithf " error %A " e
69- let assetsPath = Path.Combine( Path.GetDirectoryName( cachePath), " project.assets.json" )
70- let hash = getHash assetsPath
71-
7276
73- if cacheData.assetsHash = hash && cacheData.version = currentVersion then Ok cacheData
77+ if isCacheValid fsproj.FullName cacheJson cacheData then Ok cacheData
7478 else
7579 File.Delete( cachePath)
7680 lgInfo " Not using cached projOptions for '{proj}' because the project.assets.json hash has changed" fsproj.FullName
@@ -86,9 +90,10 @@ let tryGetCached (fsproj:FileInfo)=
8690let saveCache ( projectData : ResolvedProject ) ( fsproj : FileInfo ) =
8791 let cachePath = getCachePath fsproj.FullName
8892 let assetsPath = Path.Combine( Path.GetDirectoryName( cachePath), " project.assets.json" )
89- let hash = getHash assetsPath
93+ let assetHash = getHash assetsPath
94+ let fsprojHash = getHash fsproj.FullName
9095
91- let data = { assetsHash= hash ; Project= projectData; version= currentVersion}
96+ let data = { assetsHash= assetHash ; fsprojHash = fsprojHash ; Project= projectData; version= currentVersion}
9297 let cacheJson = Encode.Auto.toString( 4 , data, extra= extraEncoders)
9398 File.WriteAllText( cachePath, cacheJson)
9499 lgInfo " Saved cache of projectOptions for '{proj}' " fsproj.FullName
0 commit comments