@@ -1255,7 +1255,7 @@ type SqlRuntimeInfo (config : TypeProviderConfig) =
12551255 member __.RuntimeAssembly = runtimeAssembly
12561256
12571257module DesignTimeCache =
1258- let cache = System.Collections.Concurrent.ConcurrentDictionary< DesignCacheKey, Lazy< ProvidedTypeDefinition>>()
1258+ let cache = System.Collections.Concurrent.ConcurrentDictionary< DesignCacheKey, Lazy< ProvidedTypeDefinition> * DateTime >()
12591259
12601260/// The idea of this is trying to avoid case where compile-time has loaded non-runtime assembly. (Happens in .NET 8.0, not in .NET Framework.)
12611261/// So let's load compile-time (and design-time) manually the required runtime assembly.
@@ -1490,12 +1490,24 @@ type public SqlTypeProvider(config: TypeProviderConfig) as this =
14901490 // This is not a perfect cache-invalidation solution, it can remove a valid item from
14911491 // cache after the time-out, causing one extra hit, but this is only a design-time cache
14921492 // and it will work well enough to deal with Visual Studio's multi-threading problems
1493- async {
1494- do ! Async.Sleep 60000
1495- DesignTimeCache.cache.TryRemove args |> ignore
1496- } |> Async.Start
1493+ let expiration = TimeSpan.FromMinutes 3
1494+ let rec invalidationFunction key =
1495+ async {
1496+ do ! Async.Sleep ( int expiration.TotalMilliseconds)
1497+
1498+ match DesignTimeCache.cache.TryGetValue key with
1499+ | true , (_, timestamp) ->
1500+ if DateTime.UtcNow - timestamp >= expiration then
1501+ DesignTimeCache.cache.TryRemove key |> ignore
1502+ else
1503+ do ! invalidationFunction key
1504+ | _ -> ()
1505+
1506+ }
1507+ invalidationFunction args |> Async.Start
14971508 rootType
1498- try DesignTimeCache.cache.GetOrAdd( arguments, addCache) .Value
1509+ , DateTime.UtcNow
1510+ try ( DesignTimeCache.cache.GetOrAdd( arguments, addCache) |> fst) .Value
14991511 with
15001512 | e ->
15011513 let _ = DesignTimeCache.cache.TryRemove( arguments)
0 commit comments