Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Async cache fix in multi-thread-environment for GitHub downloads
  • Loading branch information
Thorium committed Aug 24, 2016
commit a3f81e335a6bbaa0ebf731f9c6c31a160b58c2d2
14 changes: 7 additions & 7 deletions src/Paket.Core/RemoteDownload.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ open Paket.Domain
open Paket.Git.CommandHelper
open Paket.Git.Handling

let private githubCache = System.Collections.Concurrent.ConcurrentDictionary<_, _>()
let private githubCache = System.Collections.Concurrent.ConcurrentDictionary<_, System.Threading.Tasks.Task<_>>()

let private lookupDocument (auth,url : string) = async {
let key = auth,url
match githubCache.TryGetValue key with
| true, document -> return document
| _ ->
let! document = safeGetFromUrl(auth, url, null)
githubCache.TryAdd(key, document) |> ignore
return document
let fetch = githubCache.GetOrAdd(key, fun key ->
let threadfix = lazy(
safeGetFromUrl(auth, url, null)
|> Async.StartAsTask |> box)
threadfix.Force() |> unbox)
return! fetch |> Async.AwaitTask
}

let private auth key url =
Expand Down