RAM preview works by caching as many frames as possible into the RAM that you've allocated to the foreground After Effects application. When the RAM preview cache is full, After Effects plays the frames from the cache.
If you want to make RAM previews longer, you can do all sorts of things, but they basically break down into two categories: allocate more RAM to After Effects or reduce the amount of memory that each frame takes up.
More information about RAM preview, memory, and performance can be found in these sections of After Effects Help:
In the end, realize that RAM preview is not suitable for playing an entire long composition at full resolution and full frame rate. Sometimes, you just have to render out a test file to see how things look.