1. A method of associating respective caching priorities to each of a plurality of states of a state machine, the method comprising: storing a state machine corresponding to one or more patterns to be detected in a data stream, wherein the state machine comprises a plurality of states; generating a test data stream based on the one or more patterns; traversing the state machine with the test data stream; determining respective hit quantities associated with each of the plurality of states, the hit quantities each indicating a number of accesses to a corresponding state by the traversing; and associating a caching priority to at least some of the plurality of states based on the hit quantities of the respective states.