Reputation: 61021
How does one handle the resource_exists
callback in cowboy? After all, to find out whether resource exists - I must query (e.g. database) for resource. But then during the AcceptResource
callback (e.g. to_html
) I must query for the resource again. Is there any way to prevent this double querying?
Is there any way to preserve that resource for the AcceptResource
callback, so that I don't have to pull it form database again?
Reading the cowboy docs, there is flowchart of how a rest request is handled.
In it, the callback resource_exists
is called first.
Upvotes: 1
Views: 438
Reputation: 5500
In resource_exists
you can add the result of the database query to the State
variable that resource_exists
returns.
The state is passed as input to the AcceptResource
callback where you can use the cached value.
Upvotes: 4