get_cache_key Function

public function get_cache_key(source_files, dependencies) result(cache_key)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: source_files(:)
character(len=*), intent(in) :: dependencies(:)

Return Value character(len=64)


Source Code

    function get_cache_key(source_files, dependencies) result(cache_key)
        character(len=*), intent(in) :: source_files(:)
        character(len=*), intent(in) :: dependencies(:)
        character(len=64) :: cache_key
        character(len=32) :: content_hash, deps_hash
        character(len=256), allocatable :: all_files(:)
        integer :: i, total_size

        ! Use content-based hashing for proper cache key generation
        ! This ensures modules with same name but different content get different cache keys

        ! Get content hash of source files
        content_hash = get_content_hash(source_files)

        ! Include dependencies in the hash if any
        if (size(dependencies) > 0) then
            ! Combine source files and dependencies for hashing
            total_size = size(source_files) + size(dependencies)
            allocate (all_files(total_size))

            ! Copy source files
            do i = 1, size(source_files)
                all_files(i) = source_files(i)
            end do

            ! Copy dependencies
            do i = 1, size(dependencies)
                all_files(size(source_files) + i) = dependencies(i)
            end do

            deps_hash = get_content_hash(all_files)
            deallocate (all_files)
        else
            deps_hash = content_hash
        end if

        ! Use the content hash as the cache key
        cache_key = trim(deps_hash)

    end function get_cache_key