Fix for the cache dependencies (file monitors) bug

This is a quick fix for the cache dependencies (FileMonitors) bug. I
have tested it, but not exhaustively (tomorrow I will do more testing).
I have committed changes so you can have a look and tell me your
thoughts about it. There is probably another way to fix it (maybe
better), but this way implies modifying the source code to a minimum.