cache: handle pkg being NULL on pkg_cache_add()/pkg_cache_remove()