Skip to content

Commit 551c7b3

Browse files
committed
minor caching update
1 parent 3dddcf6 commit 551c7b3

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/SQLProvider.DesignTime/SqlDesignTime.fs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1575,8 +1575,10 @@ type public SqlTypeProvider(config: TypeProviderConfig) as this =
15751575
LastAccess = DateTime.UtcNow.Ticks
15761576
Refreshing = 0 }
15771577

1578+
let mutable builtEntry = Unchecked.defaultof<DesignCacheEntry>
15781579
try
15791580
let entry = DesignTimeCache.cache.GetOrAdd(arguments, addCache)
1581+
builtEntry <- entry
15801582
System.Threading.Interlocked.Exchange(&entry.LastAccess, DateTime.UtcNow.Ticks) |> ignore
15811583

15821584
// Stale-while-revalidate: always serve the current tree; if it has gone stale,
@@ -1606,7 +1608,13 @@ type public SqlTypeProvider(config: TypeProviderConfig) as this =
16061608
root
16071609
with
16081610
| e ->
1609-
DesignTimeCache.cache.TryRemove(arguments) |> ignore
1611+
// Evict only this exact faulted generation by reference identity, never a fresh entry
1612+
// another thread may have inserted meanwhile. A transient failure (e.g. a momentarily
1613+
// invalid or unreachable connection) is then retried on the next access instead of the
1614+
// cached exception being served, and a concurrently-built good entry is never dropped.
1615+
if not (obj.ReferenceEquals(builtEntry, null)) then
1616+
(DesignTimeCache.cache :> System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<DesignCacheKey, DesignCacheEntry>>)
1617+
.Remove(System.Collections.Generic.KeyValuePair<DesignCacheKey, DesignCacheEntry>(arguments, builtEntry)) |> ignore
16101618
reraise()
16111619
)
16121620

0 commit comments

Comments
 (0)