Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Do you remember when you planned to buy your laptop back in your teens? You must have been into checking all the specifications and configurations of your desired devices every now and then. One of these configurations to select the better device must be the cache memory. Today, the day has finally come when we will be learning what caching is and what we mean by caching selects and aliases in the famous python framework that is web2py.
What is caching?
Cache or the cache memory is nothing but temporary storage, which is easily and quickly accessible. The data inside the cache memory is stored just below the CPU, and the process of storing the data inside the cache memory is known as caching.
It provides so many advantages such as speeding up the processes, a better and fast user experience, and also it stores the data locally. Now the question arises what do we mean by caching selects in web2py.
Caching selects
The cache argument for the select method also accepts a value of None by default. A tuple with the first element being the cache model (cache.ram, cache. disk, etc.) and the second being the expiration time in seconds should be used for caching.
We can see a controller caching a select on the previously defined db.log table in the example given below. The actual select method retrieves information from the back-end database just once every 60 seconds or so and then stores the outcome in memory. This controller merely gets the previous data from memory if the interval between calls is shorter than 60 seconds.
The cacheable argument for the select method is optional and typically False. Although the resultant Rows are serialisable when cacheable=True, they do not include update record and delete record methods.
If we do not need these methods, we can speed up the select method using the cacheable attribute with the help of the following command.
rows = db(query).select(cacheable=True)
Only the database results, not the actual Rows object, are cached when the cache parameter is set but cacheable=False (the default). The entire Rows object is cached when the cache parameter is used in conjunction with cacheable=True, which leads to substantially faster caching.
So with this, we saw how to cache selects in web2y. Let us now see what aliases in web2py are.
Aliases
As the name recommends, aliases mean a temporary name that we assign to the table or database column.
The ‘with_alias ’ method in web2py is used for making aliases of tables. This command is not restricted to making aliases of tables, and it can also be used to make aliases of fields and expressions.
Let us now discuss some of the frequently asked questions on this topic.
Frequently asked questions
What is web2py?
web2py is an open-source web application framework that focuses on rapid development by emphasizing ease of use and productivity.
web2py works on which framework?
web2py is a very flexible language. Web2py supports all the control structures that python supports. Web2py works on the full-stack framework, which is very helpful in developing database-driven web applications.
Who developed web2py?
Massimo Di Pierro developed web2py.
What is a loop?
Loop is just a way to simplify the task of repeating sets of instructions.
In which year web2py was firstly released?
In 2007 first version of web2py was released.
Conclusion
In this article, we extensively discussed web2py, which is an open-source language. Very fast, fluid in nature. We started with the introduction, and then we discussed how to cache select methods in web2py. It was then followed by learning to create aliases for the tables and expressions. In the end, we discussed a few frequently asked questions.