GeneratorGeneratortypeCreates a project, a component or configuration once, when you run it, rather than taking part in every build.See every one →What this type is →independently maintainedindependently maintainedoriginPublished by one person or a small company outside SAP. Says nothing about quality; the readings say that.See every one →

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

Last pushLicenceMIT

Where it sits

Lives in
Provides
CachingABAPCachingcapabilityHolding the result of an expensive read so the next one is cheap. This spans four different things people call caching — HTTP response caching, query result caching, remote service response caching, and application-level memoisation. They are not interchangeable, and picking the wrong one is the usual cause of stale-data bugs in multitenant apps.

Who is behind it

Furkan COSGUNFurkan COSGUNPersonMaintains this
In the atlas: maintains 6, contributes to 8
@furkancosgun
maintainer

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

Connections1

README

quoted from furkancosgun/ABAP-CACHE-BOX under MIT, read
furkancosgun/ABAP-CACHE-BOX/README.mdOn GitHub

ABAP 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_box

    Generates 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_box

    Generates 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.

MIT, read

Details

Sources3
dotabapdiscovered herechecked
github.com/furkancosgun/ABAP-CACHE-BOXtree, pushes, contributors, CIchecked
README.mdquoted, and what the entry declareschecked

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
discovered viadotabap
first seen in the atlas
ecosystem and domainabap, data-and-persistence
abaplint
issues under its own abaplint configuration147
lines338
statements379
objects3
files4
analysed, main
abaplint version2.120.84
History in the atlas1
  1. First seen.
For your agent
Ref
artifact:furkancosgun-abap-cache-box
JSON
/artifacts/furkancosgun-abap-cache-box.json
MCP
Connecting an agent