Fix postfix policyd-weight cache issues

If you're seeing maillog messages like:
cache_query: $csock couln’t be created: connect: Connection refused, calling spawn_cache()

...then you probably need to delete the socket lock files manually; sometimes this is necessary after a bad shutdown.

Find the LOCKPATH directory:
policyd-weight defaults | grep LOCKPATH
The default location is /tmp/.policyd-weight

Stop the service:
service policyd-weight stop
or
/etc/init.d/policyd-weight stop

Delete everything in the LOCKPATH directory:
rm -rf /tmp/.policyd-weight/*

Restart the service:
service policyd-weight start
or
/etc/init.d/policyd-weight start

Other problems, involving a corrupt cache and bogus cache lookup results can be solved a different way:

Kill the cache daemon:

policyd-weight -k

- should clear all cache entries. Depending on configuration you may want to do service postfix restart afterwards to be sure.

Check the cache status:

policyd-weight -s

Can also try:

policyd-weight -d

to start debug cache daemon.
This can be stopped again using:

policyd-weight -d -k