$\mu$ is a $f$-invariant measure

Let $\left(M,\sigma\left(\tau\right),\mu\right)$ a measure space where $\mu$ is a measure finite, $\tau$ is a topology in $M$, i, e, $\sigma\left(\tau\right)$ is a Borel $\sigma-$algebra. Let $\mathcal{B}\subseteq\sigma\left(\tau\right)$ a collection of open subsets such that $\sigma\left(\tau\right)$ is generated by $\mathcal{B}$, then, given $f:M\rightarrow M$ measurable, $\mu$ is $f$-invariant if and only if $\mu\left(B\right)=\mu\left(f^{-1}\left(B\right)\right)$ for all $B\in\mathcal{B}$.

Remark: If the collection $\mathcal{B}$ is a algebra, then the result is immediate. In this case there are two ways to prove this result.With this in mind the first thing I thought was to show that $\mathcal{B}$ is a algebra, but this is not always true, then i try to find a algebra containing $\mathcal{B}$ and generating $\sigma\left(\tau\right)$, but so far I failed.

It is plainly not true. Let $M=\mathbb{R}$, with the usual topology, $\mu$ is Lebesgue measure and $\mathcal{B}$ consists of all sets of the form $(r,\infty)$ with $r$ a real number. Let $f$ be given by $f(r)=2r$.