ABAP-CACHE-BOX
Macros that generate a singleton ABAP cache class for a data type or object reference, backed by a hashed internal table and exposing put, get, delete, clear and size.
Writing a cache class for every data type by hand duplicates the same singleton and lookup logic each time; generate_data_cache_box and generate_oref_cache_box generate that class instead, named after the class supplied to the macro and backed by a hashed internal table. The generated class exposes put, get, delete, clear and size, and get_instance returns its one shared instance. It stops at the generated class: the macros produce storage and lookup, nothing about expiry or persistence.
Facts
Where it sits
Who is behind it
In the atlas: maintains 6, contributes to 8@furkancosgunmaintainer
Before choosing this
Signals
ActivityQuietNo published releases; repository quiet for 26 months
It publishes no releases, and its repository has been quiet for at least 24 full months. This may be normal for stable software; check whether its current state still fits your use.
What it declares
Every artifact
- Type
- Generator
- Origin
- Independently maintained
As a generator
- Generates
- Code or test data
- Run with
- does not say
- Distributed through
- Copied into the project
Connections
Holding the result of an expensive read so the next one is cheap
Download
README
quoted from furkancosgun/ABAP-CACHE-BOX under MIT, readABAP Cache Box
This repository provides a flexible and reusable ABAP cache implementation using macros. The cache classes are dynamically generated based on the given class name and data type, making it easy to create caches for various data types without duplicating code.
Overview
The provided macros allow you to generate cache classes for different data types dynamically. This approach avoids code duplication and simplifies the process of creating cache classes for various use cases. The cache implementation uses the Singleton pattern to ensure a single instance of each cache class and employs hashed tables for efficient data access.
Features
- Dynamic Cache Generation: Use macros to generate cache classes for different data types without duplicating code.
- Singleton Pattern: Ensures a single instance of each cache class.
- Hash Table Storage: Efficient storage and retrieval of cache entries.
- Flexible Data Types: Supports various types, including value types and object references.
- Error Handling: Includes error handling for cache operations.
Installation
- Copy the cache class macros and definitions into your ABAP development environment.
- Use the provided examples to integrate and test the cache classes in your application.
Cache Class Generation
The cache classes are generated using macros. You can create a cache class for any data type by specifying the class name and data type in the macro. The class will be named using the provided class name with the suffix _CACHE_BOX.
Macro Definitions
-
generate_data_cache_boxGenerates a cache class for a value type.
Syntax:
generate_data_cache_box: <CLASS_NAME> <DATA_TYPE>.Example:
generate_data_cache_box: scarr scarr.This will generate a class named zcl_scarr_cache_box with a cache for SCARR data.
-
generate_oref_cache_boxGenerates a cache class for object references.
Syntax:
generate_oref_cache_box: <CLASS_NAME> <OBJECT_TYPE>.Example:
generate_oref_cache_box: salv cl_salv_table.This will generate a class named zcl_salv_cache_box with a cache for cl_salv_table object references.
How to Use
1. Generating and Using a Value Type Cache
To generate a cache for a specific value type, use the generate_data_cache_box macro. Here is an example of using it for the SCARR table.
REPORT sy-repid.
INCLUDE zcache_box_i_gen. "Include the macro generator
INITIALIZATION.
generate_data_cache_box: scarr scarr. " Cache for SCARR data
START-OF-SELECTION.
" Retrieve the singleton instance of the SCARR cache
DATA(lo_data_cache) = zcl_scarr_cache_box=>get_instance( ).
" Fetch data from SCARR table
SELECT * FROM scarr INTO TABLE @DATA(lt_scarr).
" Populate the cache with SCARR data
LOOP AT lt_scarr INTO DATA(ls_scarr).
lo_data_cache->put(
EXPORTING
key = CONV #( ls_scarr-carrid )
value = ls_scarr
).
ENDLOOP.
" Retrieve an entry from the cache
lo_data_cache->get(
EXPORTING
key = 'AA'
IMPORTING
value = DATA(ls_scarr_aa)
EXCEPTIONS
entry_not_found = 1
OTHERS = 2
).
IF sy-subrc EQ 0.
WRITE: / 'SCARR data for AA:', ls_scarr_aa-carrid, ls_scarr_aa-carrname.
ELSE.
WRITE: / 'Entry Not Found SCARR data for AA'.
ENDIF.
" Display the size of the cache
DATA(cache_size) = lo_data_cache->size( ).
WRITE: / 'Cache size:', cache_size.
" Delete an entry from the cache
lo_data_cache->delete(
EXPORTING
key = 'AA'
EXCEPTIONS
entry_not_found = 1
OTHERS = 2
).
IF sy-subrc EQ 0.
WRITE: / 'Entry with key AA deleted from cache.'.
ELSE.
WRITE: / 'Entry Not Found SCARR data for AA'.
ENDIF.
" Clear all entries from the cache
lo_data_cache->clear( ).
WRITE: / 'Cache cleared.'.
2. Generating and Using an Object Reference Cache
To generate a cache for object references, use the generate_oref_cache_box macro. Here is an example of using it for cl_salv_table objects.
REPORT sy-repid.
INCLUDE zcache_box_i_gen. "Include the macro generator
INITIALIZATION.
generate_oref_cache_box: salv cl_salv_table. " Cache for object references
START-OF-SELECTION.
" Retrieve the singleton instance of the reference cache
DATA(lo_oref_cache) = zcl_salv_cache_box=>get_instance( ).
SELECT * FROM scarr INTO TABLE @DATA(lt_scarr).
" Create an ALV table
cl_salv_table=>factory(
IMPORTING
r_salv_table = DATA(lo_salv)
CHANGING
t_table = lt_scarr
).
" Add the ALV table object to the cache
lo_oref_cache->put(
EXPORTING
key = 'SALV'
value = lo_salv
).
" Retrieve the ALV table object from the cache
lo_oref_cache->get(
EXPORTING
key = 'SALV'
IMPORTING
value = DATA(lo_salv2)
EXCEPTIONS
entry_not_found = 1
OTHERS = 2
).
IF sy-subrc EQ 0.
" Display the ALV table
lo_salv2->display( ).
ELSE.
WRITE : / 'Entry Not Found'.
ENDIF.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions to improve the functionality and performance of these cache classes are welcome. Please submit issues or pull requests for any enhancements or bug fixes.
Others providing
Compare all 6 on the Caching page →- Redis on SAP BTP, hyperscaler optionRedis on SAP BTP, hyperscaler optionA managed Redis from the underlying hyperscaler, consumed through a BTP service binding rather than run yourself.sap official, btpManaged Redis from the hyperscaler via a BTP service bindingfrom BTP/BAIP
- @cap-js-community/common@cap-js-community/commonSix independent features for CAP services in one package: replication cache, migration check, rate limiting, a Redis client broker, a local HTML5 repository and a CDM builder.community org, capSix CAP features in one package, from replication cache to rate limitsfrom CAP
- cds-cachingcds-cachingA caching plugin for CAP covering queries, requests, function results and remote service responses, through a read-through API or @cache annotations, with HCQL and MCP support.independent, capCAP caching plugin for query results and remote service responsesfrom CAP
- cds-data-federationcds-data-federationA data federation plugin for SAP CAP applications that declares delegation, caching and replication on a consumption view through CDS annotations, instead of hand-written handlers.independent, capData federation for CAP via delegation, caching and replicationfrom CAP
- @sap/cds@sap/cdsThe CAP Node.js runtime, which compiles the CDS model, serves the services declared in it, answers generic requests before any handler runs, and loads every cds-plugin.sap official, capCAP Node.js runtimefrom CAP
Details
Sources
Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.
Compatibility and provenance
abaplint
History in the atlas
- First seen.
For your agent
- Ref
artifact:furkancosgun-abap-cache-box- JSON
- /artifacts/furkancosgun-abap-cache-box.json
- MCP
- Connecting an agent