@@ -48,6 +48,7 @@ let settings =
48
48
ConstructorHandling= ConstructorHandling.AllowNonPublicDefaultConstructor,
49
49
Converters=[| new FileInfoConverter()|]
50
50
)
51
+
51
52
let extraEncoders =
52
53
Extra.empty
53
54
|>( Extra.withCustom
@@ -56,33 +57,35 @@ let extraEncoders=
56
57
|> Extra.withCustom
57
58
( fun ( x : Range ) -> Encode.string <| System.Text.Json.JsonSerializer.Serialize( x))
58
59
( fun path value -> Ok ( System.Text.Json.JsonSerializer.Deserialize< Range>( value.ToString()) ))
60
+
59
61
///Uses various methods to decide if the cache is still valid or if it needs to be discarded and replaced.
60
62
let isCacheValid ( fsprojPath : string ) ( cachePath : string ) ( cacheData : CacheData )=
61
63
62
64
let assetsPath = Path.Combine( Path.GetDirectoryName( cachePath), " project.assets.json" )
63
65
let assetHash = getHash assetsPath
64
66
let fsprojHash = getHash fsprojPath
65
67
cacheData.assetsHash= assetHash && cacheData.fsprojHash= fsprojHash && cacheData.version= currentVersion
68
+
66
69
///**Attempts to get cached project data.**
67
70
///
68
71
///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.
69
72
let tryGetCached ( fsproj : FileInfo )=
70
- let cachePath = getCachePath fsproj.FullName
71
- if File.Exists( cachePath ) then
72
- let cacheJson = File.ReadAllText( cachePath )
73
+ let cacheFilePath = getCachePath fsproj.FullName
74
+ if File.Exists( cacheFilePath ) then
75
+ let cacheJson = File.ReadAllText( cacheFilePath )
73
76
74
77
try
75
- let cacheData = match ( Decode.Auto.fromString( cacheJson, extra= extraEncoders)) with | Ok a-> a| Error e-> failwithf " error %A " e
78
+ let existingCacheData = match ( Decode.Auto.fromString( cacheJson, extra= extraEncoders)) with | Ok a-> a| Error e-> failwithf " error %A " e
76
79
77
- if isCacheValid fsproj.FullName cacheJson cacheData then Ok cacheData
80
+ if isCacheValid fsproj.FullName cacheFilePath existingCacheData then Ok existingCacheData
78
81
else
79
- File.Delete( cachePath )
82
+ File.Delete( cacheFilePath )
80
83
lgInfo " Not using cached projOptions for '{proj}' because the project.assets.json hash has changed" fsproj.FullName
81
84
Error " Hash had changed"
82
85
with
83
86
| e->
84
87
lgWarn2 " Cached projectOptions for '{proj}' could not be read, deleting it \n Reson {exception}" fsproj e
85
- File.Delete( cachePath )
88
+ File.Delete( cacheFilePath )
86
89
Error( sprintf " %A " e)
87
90
else Error " no cache file exists"
88
91
0 commit comments