As part of the overhaul of the WilsonORWrapper, I’m adding a cache service. To do this right, I need to implement an
ICacheClient interface. This interface will define the methods and properties which any cache client will need to implement.
Sounds simple on the surface, but I quickly ran into a problem. What do you call your methods? Consider the following possibilities for naming four core methods.
- Retrieving an item from the cache:
- Placing an item in the cache:
- Determining if an item exists in the cache:
- Remove an item from the cache:
- Clear all items from the cache:
The worst part of determining a naming convention is that you are generally stuck with it once you choose it, unless you want to implement breaking changes into your application.
Most of the names above were found in some cache API currently in existence today. (I did a Google search to find as many as possible.) Some of them are not recommended because their usage is uncommon (such as
Fetch, unless you have a
DogCacheClient). I’d also stay away from the *All methods — they sound good on paper, but the difference between
RemoveAll is quite big, and you can call the wrong one if not paying sufficient attention.
With those left over, you can organize them into groups based on similarity of use in well-known applications, languages, and APIs.
- SQL Style:
This style is good if you expect to have separate
Insertcan only add new items, and
Updateis used to change existing items.
- Collection Style:
The common naming used in Microsoft and Java collections.
- Simple Style:
Short and sweet. You can arguably combine
Clearif you’re brave.
Which one should I use for the WilsonORWrapper? One thought is to use the SQL style, since this is a wrapper for an O/R mapper, which is closely tied to SQL. However, I don’t want separate
Update methods. Also, the point of the wrapper is to allow people to write in code, not in SQL, so the relationship to SQL should not dictate style.
That leaves us with the simple style and the collections style. NHibernate uses the simple style in their Cache API. Microsoft’s System.Collections namespace uses the collection style. I’ll go with a combined version:
Clear, mostly for the reason that users of WilsonORWrapper are probably more familiar with Microsoft Collections than NHibernate, and because I prefer
Have you seen, or used, other naming conventions in your travels?