I am developing an ordering system and here is my scenario: I have a class that holds the new orders in such like a "caching" strategy. At this time, I am using a HashMap like this:
public static final Map<Long, Order> orders = new HashMap<Long, Order>();
Where I identify an order uniquely by a long
(that doesn't come from a DB, it's just an incremented variable). The reason I don't save it from DB is that for example: the employee is registering an order coming from a phone call and suddenly the customer doesn't want to order anymore, so that I won't populate my DB with an unuseful register. Based on that, I'm looking for an approach to hold all orders and "clean automatically" the indexes that are not being used anymore.
I've looked at WeakReference
but I don't know if that's what I really need. I'm open to any suggestion.
Thanks in advance.