It is unclear how do you deploy this application? A good start is https://github.com/infinispan/infinispan-quickstart/tree/master/jboss-as7
I would follow that example. Don't worry that it is as7 quickstart, it should work in Wildfly.
Thanks, I finally got it to work. The main issue was making sure the dependencies were correct. Also cache = (Cache) new InitialContext().lookup("java:module/myCache"); was the correct way to instantiate the cache which was hard to find in the documentation.