Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import redis
- from odoo import models, fields, api
- class PartnerCache(models.Model):
- _inherit = 'res.partner'
- @api.model
- def get_from_cache(self, key):
- r = redis.Redis(host='localhost', port=6379, db=0)
- return r.get(key)
- @api.model
- def set_to_cache(self, key, value):
- r = redis.Redis(host='localhost', port=6379, db=0)
- r.set(key, value)
- @api.model
- def search(self, args, offset=0, limit=None, order=None, count=False):
- # Cek apakah data sudah di-cache atau belum
- cache_key = str(args) + str(offset) + str(limit) + str(order) + str(count)
- cached_data = PartnerCache.get_from_cache(cache_key)
- if cached_data:
- return cached_data
- # Jika tidak ada di-cache, panggil fungsi asli dan simpan ke Redis cache
- data = super(ResPartner, self).search(args, offset, limit, order, count)
- PartnerCache.set_to_cache(cache_key, data)
- return data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement