@@ -161,6 +161,46 @@ defmodule Ecto.TestAdapter do
161161 end
162162end
163163
164+ defmodule Ecto.CachingTestAdapter do
165+ @ moduledoc """
166+ Test adapter that supports query caching, used for testing the query_cache option.
167+ """
168+ @ behaviour Ecto.Adapter
169+ @ behaviour Ecto.Adapter.Queryable
170+
171+ defmacro __before_compile__ ( _opts ) , do: :ok
172+
173+ def ensure_all_started ( _ , _ ) , do: { :ok , [ ] }
174+
175+ def init ( _opts ) do
176+ { :ok , Supervisor . child_spec ( { Task , fn -> :timer . sleep ( :infinity ) end } , [ ] ) , % { } }
177+ end
178+
179+ def checkout ( _mod , _opts , fun ) , do: fun . ( )
180+ def checked_out? ( _mod ) , do: false
181+
182+ def loaders ( _primitive , type ) , do: [ type ]
183+ def dumpers ( _primitive , type ) , do: [ type ]
184+ def autogenerate ( :id ) , do: nil
185+ def autogenerate ( :embed_id ) , do: Ecto.UUID . autogenerate ( )
186+ def autogenerate ( :binary_id ) , do: Ecto.UUID . bingenerate ( )
187+
188+ # Return :cache to trigger default caching in the planner
189+ def prepare ( operation , query ) , do: { :cache , { operation , query } }
190+
191+ def execute ( _adapter_meta , _query_meta , { _cache_status , { :all , _query } } , _dump_params , _opts ) do
192+ [ ]
193+ end
194+
195+ def execute ( _adapter_meta , _query_meta , { _cache_status , { _operation , _query } } , _dump_params , _opts ) do
196+ { 1 , nil }
197+ end
198+
199+ def stream ( _adapter_meta , _query_meta , _prepared , _dump_params , _opts ) do
200+ [ ]
201+ end
202+ end
203+
164204Application . put_env ( :ecto , Ecto.TestRepo , user: "invalid" )
165205
166206defmodule Ecto.TestRepo do
0 commit comments