Fix for bogus "symlink attack" error on Windows (bug #18834)

Also another unpleasant issue is fixed: if the cache file was actually a symlink, it was truncated (due to opening in 'wb' mode) **before** a check for symlink was made.

A test is available as well, unfortunately it needs either Admin rights or updated security policy to run on Windows.