OldGuy: freeze rice, beans, flour and such when you bring it home. Let it chill for a week, then put it into buckets with some silica gel packets and seal tightly. I keep several hundred pounds of each and after learning this trick, havent had any issues with bugs.
Another thought: For coarse products like beans and rice, toss in a half a cup of diatomaceous earth, cap and shake well. Used or not, shake the container every month or so to mix it up a bit. As you use the product rinse it well to get the DE off. FYI, DE has amazingly sharp edges (check it out under a microscope!) and basically cuts any emergent bugs to ribbons within a day or two. Harmless to people too, but it is gritty which is why you should rinse it off before cooking.
"Resistance is futile. You will be commodified"..."
c.f Larry Harvey, The BMOrg