Gorenstein algebras and the Cayley-Bacharach theorem