Enable Dark Mode!
how-to-store-values-in-the-pos-cache-in-odoo-18.jpg
By: Mohammed Farhan

How to Store Values in the POS Cache in Odoo 18

Technical Odoo 18 POS

The Point of Sale (POS) system in Odoo 18 leverages an efficient caching mechanism to store frequently accessed data in memory, enhancing performance and responsiveness. By reducing database queries and optimizing data retrieval, caching ensures smoother operations in high-traffic retail environments.

Key Benefits of Using POS Cache in Odoo 18

Faster Data Access

  • Cached data is retrieved from memory instead of the database, reducing latency and speeding up transactions.
  • This leads to quicker order processing, improving overall POS efficiency.
  • Reduced Database Load

  • By minimizing repeated database calls, caching helps maintain system stability, especially during peak hours.
  • This improves scalability, allowing multiple users to operate the POS simultaneously without performance degradation.
  • Enhanced User Experience

  • A responsive POS system ensures seamless checkout experiences for customers and cashiers.
  • Faster transactions lead to higher customer satisfaction and increased sales.
  • Optimized Resource Utilization

  • Caching reduces the need for additional hardware by efficiently managing system resources.
  • This makes the POS system more cost-effective while maintaining high performance.

How to Store and Retrieve Values in Odoo 18 POS Cache

Odoo 18 provides multiple ways to manage cached data in the POS module. Below are different methods to store and retrieve values using the pos object and cache utilities.

Storing and Retrieving Order-Specific Data

You can store temporary data related to an order using the pos object.

Storing a Value in the Current Order

import { usePos } from "@point_of_sale/app/store/pos_hook"; // import usePos
this.pos = usePos();
this.pos.get_order().order_note = 'Special instructions';

Retrieving the Stored Value

var note = this.pos.get_order().order_note;
console.log(note);

Storing Cashier-Specific Data

If you need to store temporary data related to the logged-in cashier, you can use:

Storing a Value for the Cashier

this.pos.get_cashier().preferences = { discount_access: true };

Retrieving the Cashier’s Data

var cashierPrefs = this.pos.get_cashier().preferences; 
console.log(cashierPrefs.discount_access);

Using the Cache Utility for Advanced Caching

Odoo 18 introduces a dedicated Cache utility for more structured caching.

Importing and Initializing the Cache

import { Cache } from "@web/core/utils/cache";
setup() {
  super.setup();
  this.pos.cache = new Cache((key) => null);
},

Storing a Value in Cache

setCacheValue(key, value) {
   this.pos.cache.clear(key);
   this.pos.cache.read(key);
   const { cache } = this.pos.cache._getCacheAndKey(key);
   cache[key] = value;
},
// Example usage:
this.setCacheValue('loyalty_points', 500);

Retrieving a Value from Cache

getCacheValue(key) {
   return this.pos.cache.read(key);
},
// Example usage: 
var points = this.getCacheValue('loyalty_points'); 
console.log(points);

Clearing Cache Data

The POS cache is temporary and automatically clears when the session ends. However, you can manually remove cached data if needed.

this.pos.cache.invalidate(); // Removes all
this.pos.cache.clear('loyalty_points');  // Removes a specific key

Using the POS cache in Odoo 18 significantly improves performance by reducing database load and accelerating data access. Whether storing order details, cashier preferences, or custom key-value pairs, the caching mechanisms ensure a smoother and more efficient POS experience.

By leveraging these techniques, businesses can enhance transaction speed, reduce hardware strain, and provide a seamless checkout process for customers.

To read more about How to Store Values in POS Cache in Odoo 17, refer to our blog How to Store Values in POS Cache in Odoo 17.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message