In this example, we will enhance the wiki engine that we have been developing by writing a service that retrieves wiki text from the database and converts it to HTML. Then, to limit the load on our infrastructure, we will add caching support.
First, we need to code our service. The service will call a data access component to retrieve the wiki text stored in our database. Then we will convert it to HTML and hand it back to the caller.
class WikiService(object): def __init__(self, data_access): self.data_access = data_access def get_article(self, article): return self.data_access.retrieve_wiki_text(article) def store_article(self, article): self.data_access.store_wiki_text(article) def html(self, text): pass # return wiki text converted to HTML def statistics(self, article): hits = self.data_access.hits(article) return (hits, hits / len(self.data_access.edits...