- Kivy Tutorial
- Kivy - Home
- Kivy Basics
- Kivy - Getting Started
- Kivy - Installation
- Kivy - Architecture
- Kivy - File Syntax
- Kivy - Applications
- Kivy - Hello World
- Kivy - App Life Cycle
- Kivy - Events
- Kivy - Properties
- Kivy - Inputs
- Kivy - Behaviors
- Kivy Buttons
- Kivy - Buttons
- Kivy - Button Events
- Kivy - Button Colors
- Kivy - Button Size
- Kivy - Button Position
- Kivy - Round Buttons
- Kivy - Disabled Buttons
- Kivy - Image Button
- Kivy Widgets
- Kivy - Widgets
- Kivy - Label
- Kivy - Text Input
- Kivy - Canvas
- Kivy - Line
- Kivy - Checkbox
- Kivy - Dropdown List
- Kivy - Windows
- Kivy - ScrollView
- Kivy - Carousel
- Kivy - Slider
- Kivy - Images
- Kivy - Popup
- Kivy - Switch
- Kivy - Spinner
- Kivy - Splitter
- Kivy - Progress Bar
- Kivy - Bubble
- Kivy - Tabbed Panel
- Kivy - Scatter
- Kivy - Accordion
- Kivy - File Chooser
- Kivy - Color Picker
- Kivy - Code Input
- Kivy - Modal View
- Kivy - Toggle Button
- Kivy - Camera
- Kivy - Tree View
- Kivy - reStructuredText
- Kivy - Action Bar
- Kivy - Video Player
- Kivy - Stencil View
- Kivy - VKeyboard
- Kivy - Touch Ripple
- Kivy - Audio
- Kivy - Videos
- Kivy - Spelling
- Kivy - Effects
- Kivy - Input Recorder
- Kivy - OpenGL
- Kivy - Text
- Kivy - Text Markup
- Kivy - Settings
- Kivy Layouts
- Kivy - Layouts
- Kivy - Float Layout
- Kivy - Grid Layouts
- Kivy - Box Layouts
- Kivy - Stack Layout
- Kivy - Anchor Layout
- Kivy - Relative Layout
- Kivy - Page Layout
- Kivy - Recycle Layout
- Kivy - Layouts in Layouts
- Kivy Advanced Concepts
- Kivy - Configuration Object
- Kivy - Atlas
- Kivy - Data Loader
- Kivy - Cache Manager
- Kivy - Console
- Kivy - Animation
- Kivy - Multistroke
- Kivy - Clock
- Kivy - SVGs
- Kivy - UrlRequest
- Kivy - Clipboard
- Kivy - Factory
- Kivy - Gesture
- Kivy - Language
- Kivy - Graphics
- Kivy - Drawing
- Kivy - Packaging
- Kivy - Garden
- Kivy - Storage
- Kivy - Vector
- Kivy - Utils
- Kivy - Inspector
- Kivy - Tools
- Kivy - Logger
- Kivy - Framebuffer
- Kivy Applications and Projects
- Kivy - Drawing App
- Kivy - Calculator App
- Kivy - Stopwatch App
- Kivy - Camera Handling
- Kivy - Image Viewer
- Kivy - Bezier
- Kivy - Canvas Stress
- Kivy - Circle Drawing
- Kivy - Widget Animation
- Kivy - Miscellaneous
- Kivy Useful Resources
- Kivy - Quick Guide
- Kivy - Useful Resources
- Kivy - Discussion
Kivy - Cache Manager
In Kivy framework, the Cache class stores one or more Python objects by assigning them as value of a unique key. Kivy's Cache manager controls the objects in it by either imposing a limit to the number of objects in it, or keeping a timeout limit to their access.
The Cache class is defined in the "kivy.cache" module. It includes the static methods: register(), append(), get(), etc.
To start with, you need to register a Category in the Cache manager by setting the maximum number of objects and the timeout.
from kivy.cache import Cache Cache.register(category='mycache', limit=10, timeout=5)
You can now add upto 10 Python objects, each with a unique key.
key = 'objectid' instance = Label(text=text) Cache.append('mycache', key, instance)
The get() method retrieves an object from the cache.
instance = Cache.get('mycache', key)
The Cache class defines the following methods and properties −
register() Method
This method registers a new category in the cache with the specified limit. It has the following parameters −
category − A string identifier of the category.
limit − Maximum number of objects allowed in the cache. If None, no limit is applied.
timeout − Time after which the object will be removed from cache.
append() Method
This method add a new object to the cache. Following parameters are defined −
category − string identifier of the category.
key − Unique identifier of the object to store.
obj − Object to store in cache.
timeout − Time after which to object will be deleted if it has not been used. This raises ValueError if None is used as key.
get() Method
This method is used to get a object from the cache, with the following parameters −
category − string identifier of the category..
key − Unique identifier of the object in the store..
default − Default value to be returned if the key is not found.
Example
Take a look at the following example −
from kivy.cache import Cache from kivy.uix.button import Button from kivy.uix.label import Label Cache.register(category='CacheTest', limit=5, timeout=15) b1 = Button(text='Button Cache Test') Cache.append(category='CacheTest', key='Button', obj=b1) l1 = Label(text='Label Cache Test') Cache.append(category='CacheTest', key='Label', obj=l1) ret = (Cache.get('CacheTest', 'Label').text) print (ret)
Output
It will produce the following output −
Label Cache Test
To Continue Learning Please Login
Login with Google