Databases Reference
In-Depth Information
Use cached data
Yes
In
cache?
Calculate
hash
Cache
No
Store for
future use
Input
Output
Transform
data
Data
Transform pipeline
Only used if not
in cache
Figure 10.11 You can use referential transparency to increase the performance of any
transform by checking to see if the output of a transform is already in a cache. If it's
in the cache, you can use the cached value instead of rerunning an expensive
transformation process. If the item isn't in the cache, you can store it in a RAM cache
such as memcache to reuse the output.
10.2
Case study: using NetKernel
to optimize web page content assembly
This case study looks at how functional programming and REST services can be com-
bined to optimize the creation of dynamic nested structures. We'll use as an example
the creation of a home page for a news-oriented website. We'll look at how an
approach called resource-oriented computing ( ROC ) is implemented by a commercial
framework called NetKernel.
10.2.1
Assembling nested content
and tracking component dependencies
Let's assume you're running a website that displays news stories in the center of a web
page. The web page is dynamically assembled using page headers, footers, navigation
menus, and advertising banners around the news content. A sample layout is shown in
the left panel of figure 10.12. You use a dependency tree, as shown in the right panel
of figure 10.12, to determine when each web page component should be regenerated.
Though we think of public URL s as identifying web pages and images, you can use
this same philosophy with each subcomponent in the dependency tree by treating
each component as a separate resource and assigning it an internal identifier called a
uniform resource identifier ( URI ) . In the web page model, each region of the web page is a
resource that can be assembled by combining other static and dynamic resources.
Each distinct resource has its own URI .
In the previous section, you saw how functional programming uses referential
transparency to allow cached results to be used in place of the output of a function.
We'll apply this same concept to web page construction. You can use URI s to check
whether a function call has already been executed on the same input data, and you
can track dependencies to see when functions call other functions. If you do this, you
Search WWH ::




Custom Search