If you access your database via JPA, you can use WildFly's distributed second-level cache which will do all of this for you.
I do not understand how any piece of software in wildfly would know to do anything if I simply run a SQL statement on the underlying database. Can you please elaborate on how that is the case?
I didn't say anything about running a SQL statement via JDBC. I said that, if you use JPA for database access, you can leverage Hibernate's 2nd-level cache to perform caching/invalidation for you.
Using a remote cache to persist entities largely defeats the purpose of this level of caching, since it requires a network call to access the cached data.