Will setcookie work if there is a cache plugin installed?

It will most likely depend on the plugin, but you should also remember that your content might be cached also in caching proxies as well. https://stackoverflow.com/questions/9334393/proxy-cacheing-what-about-cookies

In other words, if your output is different to two different users, than you can not use caching. The way to go around this is to make the decision to set the cookie in JS if possible.