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.
"To sum up my compassion level, I think we should feed the unwanted animals to the homeless. Or visa versa. Too much attention and money is spent on both."
(A Beautiful Mind)