result of to_tsquery() can't be used as a cache key, since ts_query() does preserve an order, which isn't good for cacheing. For example,
=# select to_tsquery('cache & query') = to_tsquery('query & cache'); ?column? ---------- f
Little function (kudos to Teodor) helps:
CREATE OR REPLACE FUNCTION stable_ts_query(tsquery) RETURNS tsquery AS $$ SELECT ts_rewrite( $1 , 'dummy_word', 'dummy_word'); $$ LANGUAGE SQL RETURNS NULL ON NULL INPUT IMMUTABLE;
Of course, you should remember about search configuraton to have really good cache key !