 (defn ^Session connect
   "Connects to the Cassandra cluster. Use `build` function to build cluster with all required options."
   ([^Cluster cluster]
+     (flush-prepared-statement-cache!)
      (.connect cluster))
   ([^Cluster cluster keyspace]
+     (flush-prepared-statement-cache!)
      (.connect cluster (name keyspace))))
 
 (defn connect!
   "Connects and sets *default-cluster* and *default-session* for default cluster and session, that
    cql/execute is going to use."
   [hosts & {:keys [keyspace] :as options}]
+  (flush-prepared-statement-cache!)
   (let [cluster (build-cluster (assoc options :contact-points hosts))
         session (if keyspace
                   (connect cluster keyspace)

            LoggingRetryPolicy DefaultRetryPolicy DowngradingConsistencyRetryPolicy FallthroughRetryPolicy
            RetryPolicy ConstantReconnectionPolicy ExponentialReconnectionPolicy]))

;;
;; Load Balancing policies
;;

  ([^String query]
     (prepare *default-session* query))
  ([^Session session ^String query]
     (if-let [cached (get @prepared-statement-cache [session query])]
       cached
       (let [prepared (.prepare ^Session session query)]
         (swap! prepared-statement-cache #(assoc % [session query] prepared))
         prepared))))

(defn build-cluster
  "Builds an instance of Cluster you can connect to.
