@@ -12,6 +12,7 @@ open Types
12
12
type CacheData = {
13
13
///hash of the projects assets.json. This is used to see if the project has changed which would invalidate our hash.
14
14
assetsHash : string
15
+ fsprojHash : string
15
16
Project: ResolvedProject
16
17
///Used to allow deleting of old cache data if we make significant changes
17
18
version: string
@@ -55,7 +56,13 @@ let extraEncoders=
55
56
|> Extra.withCustom
56
57
( fun ( x : Range ) -> Encode.string <| System.Text.Json.JsonSerializer.Serialize( x))
57
58
( 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 )=
58
61
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
59
66
///**Attempts to get cached project data.**
60
67
///
61
68
///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)=
66
73
67
74
try
68
75
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
-
72
76
73
- if cacheData.assetsHash = hash && cacheData.version = currentVersion then Ok cacheData
77
+ if isCacheValid fsproj.FullName cacheJson cacheData then Ok cacheData
74
78
else
75
79
File.Delete( cachePath)
76
80
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)=
86
90
let saveCache ( projectData : ResolvedProject ) ( fsproj : FileInfo ) =
87
91
let cachePath = getCachePath fsproj.FullName
88
92
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
90
95
91
- let data = { assetsHash= hash ; Project= projectData; version= currentVersion}
96
+ let data = { assetsHash= assetHash ; fsprojHash = fsprojHash ; Project= projectData; version= currentVersion}
92
97
let cacheJson = Encode.Auto.toString( 4 , data, extra= extraEncoders)
93
98
File.WriteAllText( cachePath, cacheJson)
94
99
lgInfo " Saved cache of projectOptions for '{proj}' " fsproj.FullName
0 commit comments